|
I posted a question yesterday on scaling and
translating, I think I have found my answer.
I don't understand all the details, but it looks
like after calling the scale( ), the translate( ) call must also be
scaled:
protected void
paintComponent(Graphics g)
{ super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
final
int width = bufImage.getWidth(
);
final int height = bufImage.getHeight( ); final float zoomFactor = getZoomFactor( ); //
translate by half the 'growth'
float translateX = 0.5f * ((width * zoomFactor) - width); float translateY = 0.5f * ((height * zoomFactor) - height); // make
image larger
g2.scale(zoomFactor, zoomFactor); // keep
image center centered
g2.translate( - (translateX * (1/zoomFactor)), - (translateY * (1/zoomFactor)) ); g2.drawImage(bufImage, 0, 0, this); } In the above code, I multiply my translateX and
translateY by the inverse of the zoomFactor which was used to do the scaling.
Now as the image gets bigger, it stays centered.
Ted Hill
|
- [JAVA2D] scale and translate question Ted Hill
- Re: [JAVA2D] scale and translate question Ted Hill
- Re: [JAVA2D] scale and translate question Jim Bucher
- Re: [JAVA2D] scale and translate question Jim Graham
- Re: [JAVA2D] scale and translate question Steven Owens
- Re: [JAVA2D] scale and translate question Jim Graham
- Re: [JAVA2D] scale and translate question Steven Owens
- Re: [JAVA2D] scale and translate question Mark Lentczner
- Re: [JAVA2D] scale and translate question Jean Adams
- Re: [JAVA2D] scale and translate question Jean Adams
- Re: [JAVA2D] scale and translate question Jean Adams
