Java - Anamorphism (image manipulation)

Asked

Viewed 73 times

1

Good evening, I’m creating an application for a specific goal, which manipulates image, I’m using methods such as:

image.BufferedImage
Graphics2D
RenderingHints

In this context I’m taking a specific image for example

Manipulating her and transforming her like this

Generating an anamorphism, however I am doing as follows, rotating the image at the desired angle, then stretching it laterally to the desired ratio and returning to the angle the original, for example, this rotation (40.0 degrees) then stretched 20% and des-rotacionei (-40.0 degrees), there is this effect of anamorphism and I saved the image in the desired folder, I wonder if there is any other method that only putting the angle it makes the anamorphism alone without all this work?

What I am using (Bufferedimage resize) (Bufferedimage rotateMyImage)

 public static BufferedImage resize(BufferedImage img, String outputFileLocation, String extension){

    int new_largura = img.getWidth();
    int new_altura = img.getHeight();

    int mat = new_largura + ((new_largura *50)/100);
    new_largura = new_largura + mat;

    BufferedImage new_img;

    new_img = new BufferedImage(new_largura, new_altura, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2d = new_img.createGraphics();
    graphics2d.drawImage(img, 0, 0, new_largura, new_altura, null);

    writeImage(new_img, outputFileLocation, "png");

    return img;
}


public static BufferedImage rotateMyImage(BufferedImage img, double angle, String outputFileLocation) {
    int w = img.getWidth();
    int h = img.getHeight();
    int iw = w+200;
    int ih = h+200;
    BufferedImage dimg =new BufferedImage(iw, ih, img.getType());
    Graphics2D g = dimg.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
            RenderingHints.VALUE_ANTIALIAS_ON);

    g.rotate(Math.toRadians(angle), iw/2, ih/2);

    // ensure image will fit
    int dw = w;
    int dh = h;
    if (dw > iw) {
        dh = (int)(dh * ( (float) iw / (float) dw)) ;
        dw = iw;
    }
    if (dh > ih) {
        dw = (int)(dw * ( (float) ih / (float) dh)) ;
        dh = ih;
    }
    // centre on page
    int dx = (iw - dw) / 2;
    int dy = (ih - dh) / 2;

    g.drawImage(img, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);

    writeImage(dimg, outputFileLocation, "png");

    //g.drawImage(img, null, 0, 0);
    return dimg;
}

OK works, but I need to enter several folders from 0-0, 0-1.... 0-4...up to folder 10-10 and each folder has 131 image files, each folder represents a different angle to distort and make the anamorphism and need to take the image, make the anamorphism and save it superimposing the original on each image, are approximately 14440 images, wanted to facilitate the process because it is consuming too much of the computer giving processing error before it ends, besides being too much loop work (for) to run, wanted to know if there is any method for this activity?

I appreciate all your help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.