Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

image file rotation  RSS feed

 
adnanqazi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am supposed to read an image from a file , rotate it and overwrite the existing file with a rotated version, i use java2D api, the result is a blur rotated file with 3/4 black portion added to it vertically,
here's the code.
Would apprecite help.
BufferedImage bi=this.readImage(filename);
//reading and writng is fine because i do get the same file intact if i comment out the rotating code
int y=bi.getHeight();
int x= bi.getWidth();
AffineTransform tx = new AffineTransform();
tx.rotate(1.57, x/2,y/2);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
bi = op.filter(bi, null);
this.writeToFIle();
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"adnan99photo" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your image height and width is not the same parts of the image get cut off... you'll have to copy the image into another image that is big enough to fit the rotated image and then rotate that. Here's some example code that should help.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!