So i’ve been trying for over a day to solve this issue and i’m about to cry lol (ok maybe not that dramatic but close enough).
I’m trying to rotate an image but everytime i try no matter the method or it either truncates or it doesn’t resize.
This is what i’m doing in general:
i have an image wich is (let say) 150 x 300 then when i draw it i resize to about 55% of its original size.
but on double click i have to rotate it 90 degrees (goes back and forth to 90 degrees, -horizontal and vertical position-)
and i have tried 2 methods but i get undesired behavior:
this is one:
cardImage is the original full-sized card.
flippedCardImage is where i store the flipped version of cardImage.
public void rotateImage (double degrees){
ImageIcon icon = new ImageIcon(cardImage);
BufferedImage blankCanvas = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D)blankCanvas.getGraphics();
g2.rotate(Math.toRadians(degrees), icon.getIconWidth()/2, icon.getIconHeight()/2);
g2.drawImage(cardImage, 0, 0, null);
flippedCardImage = blankCanvas;
}
with that code i get the image but it is shrinked.
and with this:
public BufferedImage rotateImage(BufferedImage img, double degrees) {
//making image with the rotated size
BufferedImage rotated = new BufferedImage((int) cd.getSCD().getHeight(), (int) cd.getSCD().getWidth(), img.getType());
//We create a Graphics2D object...
Graphics2D f = rotated.createGraphics();
f.translate(rotated.getWidth()/2, rotated.getHeight()/2); //translate half the width and height
f.rotate(Math.toRadians(degrees)); //rotate the image...
f.translate(-img.getWidth()/2, -img.getHeight()/2); //translate-back to half the original width and height
f.drawImage(img, 0, 0, null); //draw image
f.dispose();
return rotated;
}
with that when i draw it it draws like if i cropped the 55% sized rectangle off the full sized image and draw that instead of resize it.
how do i do rotate and resize it properly can someone please help me? T_T