Skip to main content

[JAVA2D] SetToScale problem....AffineTransform

1 reply [Last post]
Anonymous

Hi all,

Im writing a portion of my program tos acle a JPEG image down to fit
within a small viewerPane. When I use the setToScale method, and I try
to scle the image down but maintain the sacled aspect ratio it takes
much longer and causes other problems in my program as compared to when
I do a setToScale to make the image TO_FIT the viewerPane. Anyone know
why this is...is there a bug that I don't know about? Maybe another way
to do this so that it works properly?

Its very strange because the only thing that changes is the mag
pararmeter to setToScale()....when the parameters are set for TO_FIT, it
works perfectly, but anyother mag values make the program go extremely
slow. Any help would be much appreciated...I'm stumped. Thanks

Below is the code where I do the setToScale transformation.:

switch(displayMode){
case DisplayMode.ORIG_SIZE:
bufferWid = imageWidth;
bufferHt = imageHeight;
break;
case DisplayMode.SCALED:
double mag= (magY > magX)? magX:magY;
System.out.println("magX:"+magX);
System.out.println("magY:"+magY);
System.out.println("mag:"+mag);
dispModeAtx.setToScale(mag, mag);
//dispModeAtx.setToScale(mag/magX, mag/magY);
bufferWid = (int)(imageWidth*mag);
bufferHt = (int)(imageHeight*mag);
System.out.println("bw:"+bufferWid);
System.out.println("bh:"+bufferHt);
break;
case DisplayMode.TO_FIT:
dispModeAtx.setToScale(magX, magY);
bufferWid = width;
bufferHt = height;
System.out.println("bw:"+bufferWid);
System.out.println("bh:"+bufferHt);
default:
break;
}

//atx.translate(-(this.getWidth()-bufferWid)/2, -(this.getHeight()
- bufferHt)/2);
BufferedImage bi = new BufferedImage(bufferWid,
bufferHt,imageType);
Graphics2D bigc = bi.createGraphics();
if(originalImageType == TYPE_AWT_IMAGE) bigc.drawImage(awtImage,
dispModeAtx, this);
else bigc.drawImage(bufferedImage, dispModeAtx, this);

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jim Graham

It's hard to diagnose this problem without a complete example to run, but I
can make some guesses and recommendations.

Which release are you running this on? The reason I ask is that there is
an image scaling regression in JDK 1.5.0 that causes us to use a slightly
slower rendering path when the coordinates of an image operation do not
fall on integer boundaries. If the same code runs fine on JDK 1.4.2 then
you are likely to be running into this bug:

The workaround is to use the drawImage(x, y, w, h) variant instead of using
an AffineTransform to scale the image. The bug report has more details...

...jim

--On Wednesday, October 27, 2004 12:24 PM +0200 "Braun-Friedman, David"
wrote:
> Hi all,
>
> Im writing a portion of my program tos acle a JPEG image down to fit
> within a small viewerPane. When I use the setToScale method, and I try
> to scle the image down but maintain the sacled aspect ratio it takes much
> longer and causes other problems in my program as compared to when I do a
> setToScale to make the image TO_FIT the viewerPane. Anyone know why this
> is...is there a bug that I don't know about? Maybe another way to do
> this so that it works properly?
>
> Its very strange because the only thing that changes is the mag
> pararmeter to setToScale()....when the parameters are set for TO_FIT, it
> works perfectly, but anyother mag values make the program go extremely
> slow. Any help would be much appreciated...I'm stumped. Thanks
>
> Below is the code where I do the setToScale transformation.:
>
> switch(displayMode){
> case DisplayMode.ORIG_SIZE:
> bufferWid = imageWidth;
> bufferHt = imageHeight;
> break;
>
> case DisplayMode.SCALED:
> double mag= (magY > magX)? magX:magY;
> System.out.println("magX:"+magX);
> System.out.println("magY:"+magY);
> System.out.println("mag:"+mag);
> dispModeAtx.setToScale(mag, mag);
> //dispModeAtx.setToScale(mag/magX, mag/magY);
> bufferWid = (int)(imageWidth*mag);
> bufferHt = (int)(imageHeight*mag);
> System.out.println("bw:"+bufferWid);
> System.out.println("bh:"+bufferHt);
> break;
>
> case DisplayMode.TO_FIT:
> dispModeAtx.setToScale(magX, magY);
> bufferWid = width;
> bufferHt = height;
> System.out.println("bw:"+bufferWid);
> System.out.println("bh:"+bufferHt);
> default:
> break;
> }
>
> //atx.translate(-(this.getWidth()-bufferWid)/2, -(this.getHeight()
- bufferHt)/2);
> BufferedImage bi = new BufferedImage(bufferWid,
bufferHt,imageType);
> Graphics2D bigc = bi.createGraphics();
> if(originalImageType == TYPE_AWT_IMAGE) bigc.drawImage(awtImage,
dispModeAtx, this);
> else bigc.drawImage(bufferedImage, dispModeAtx, this);

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".