File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about drawimage

 
zhong hb
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to draw a image on a rectangle,the code is:

int x = rectangle.getX();
int y = rectangle.getY();

int w = rectangle.getWidth();
int h = rectangle.getHeidht();

ImageIcon icon = new ImageIcon(imageName);
Image image = icon.getImage();

AffineTransform at = new AffineTransform();
at.translate(x,y);
at.scale(w/image.getWidth(this),h/image.getHeight(this));
graphics2d.drawImage(image,at,this);

because the forum can't show image, I take a char 'A' to replace image.under jre1.4.1, the result is 'A',which is good. but under jre1.5.0,'A''A''A'is showing. Why?? Thanks!
 
Craig Wood
Ranch Hand
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't post images to this forum?

News to me!
 
zhong hb
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I find that AffineTransform is a key for image showing.
if the scale is suitable, the showing is good.
[ November 10, 2005: Message edited by: zhong hb ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic