On Dec 3, 2:36 pm, Knute Johnson <nos...@rabbitbrush.frazmtn.com>
wrote:
ErcF...@gmail.com wrote:
Hello. I have an application that creates a bufferedimage, but most of
the times it's to big to print all on one page. What I want to do is
scale it to fit on one page. If anyone could show me some example code
on how to do this it would be appreciated. (I have the basic
understanding that I need to get the printable area of the printer and
then scale the image to fit in that but I'm not sure how to implement
this.) Thanks.
From the docs:
drawImage(Image img, int x, int y, int width, int height, ImageObserver
observer)
Draws as much of the specified image as has already been scaled to fit
inside the specified rectangle.
--
Knute Johnson
email s/nospam/knute/
I guess I'm not quite sure what you're saying I should do. Here is the
code for what I was trying to do:
<code> public BufferedImage resizeImage(BufferedImage bimg)
{
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.LANDSCAPE);
MediaPrintableArea printableArea =
(MediaPrintableArea)Service.getSupportedAttributeValues(MediaPrintableArea.class,
null, aset);
double printWidth = printableArea.getWidth(MediaPrintableArea.INCH);
double printHeight =
printableArea.getHeight(MediaPrintableArea.INCH);
int tempW = bimg.getWidth();
int tempH = bimg.getHeight();
double bimgWidth = tempW/72;
double bimgHeight = tempH/72;
double conversion;
double Xconv = printWidth/bimgWidth;
double Hconv = printHeight/bimgHeight;
if(Xconv > Hconv)
conversion = Xconv;
else
conversion = Hconv;
int bimgNewW = conversion*tempW;
int bimgNewH = conversion*tempH;
BufferedImage newbimg = bimg.getScaledInstance(bimgNewW, bimgNewH,
BufferedImage.SCALE_DEFAULT);
return newbimg;
}</code>