0

I am working on image processing . I have a buffered image of fixed size

BufferedImage targetImage = new BufferedImage(320, 240,BufferedImage.TYPE_INT_RGB);

Lets say Original Buffered image is of size 180 by 240 .

Now I want to load Original Image(180X240) to target Image(320X240) or somehow change scaledImage width and height to 320 by 240 which will have white padding at bottom.

Thanks in advance.

stacker
  • 68,052
  • 28
  • 140
  • 210
Pit Digger
  • 9,618
  • 23
  • 78
  • 122
  • So, you just want to draw the smaller image into the larger image, while scaling it? This tutorial explains how to do that: [Drawing an Image](http://download.oracle.com/javase/tutorial/2d/images/drawimage.html) – Jesper May 02 '11 at 14:14

1 Answers1

4

You should be able to "paint" the source image into the target image, i.e.

targetImage.getGraphics().drawImage(sourceImage, 0, 0, 
   Math.min(targetImage.getWidth(), sourceImage.getWidth()), 
   Math.min(targetImage.getHeight(), sourceImage.getHeight()),
   null);

Note that increasing 180x240 to 320x240 would mean that you'd either distort the image, cut part of the image at the top/bottom or have some "empty" area to the left/right (not to the top/bottom).

Thomas
  • 87,414
  • 12
  • 119
  • 157
  • I just needed to draw image to original size and than pad it to right or bottom if image is smaller . So in that case it wont be distorted. – Pit Digger May 02 '11 at 14:39