Minibild erstellen

IMAGEJ (JAVA)



/* Copyright Jürgen Reule 2011-2023 */
   
import java.awt.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.io.File;
   
public class Minibild {
   
    //   0   Bild-Pfad
    //   1   Minibild-Pfad
    //   2   Minibild-Art (jpeg/gif/...)
    //   3   Minibild Maximale Breite
    //   4   Minibild Maximale Höhe
   
    public static void main(String args[]) throws Exception {
   
        BufferedImage image = ImageIO.read(new File(args[0]));
   
        int maxWidth  = Integer.parseInt(args[3]);
        int maxHeight = Integer.parseInt(args[4]);
   
        float w = image.getWidth();  float w1 = w;
        float h = image.getHeight(); float h1 = h;
   
        if (w1 > maxWidth) {
            w1 = maxWidth;
            h1 = maxWidth * h/w;
        }
        if (h1 > maxHeight) {
            h1 = maxHeight;
            w1 = maxHeight * w/h;
        }
        int w2 = Math.round(w1);
        int h2 = Math.round(h1);
   
        Image scaled =
        image.getScaledInstance(w2, h2,
        Image.SCALE_SMOOTH);
   
        BufferedImage preview = new
        BufferedImage(w2, h2,
        BufferedImage.TYPE_INT_RGB);
   
        preview.getGraphics().drawImage(
        scaled, 0, 0, w2, h2, Color.white, null);
   
        ImageIO.write(preview, args[2], new File(args[1]));
    }
}

43 ms | Kontakt | Information | Aibo-Bar © 2005-2024