2011-03-31 72 views

回答

1

我想你会需要“退”你的比例系数由搞清楚什么规模将让你的高度为300个像素,你的宽度为100

喜欢的东西

double xScale = 100/image.getWidth(); 
double yScale = 300/image.getHeight(); 

AffineTransform transform = new AffineTransform(); 
transform.setToScale(xScale, yScale); 
//paint code goes here 

这不会虽然规模统一。要做到这一点,你需要对x和y使用相同的比例。因此,如果您试图确保您的图片适合屏幕/显示/页面,您将采用最宽广的尺寸。 于是就用上面的例子...

double xScale = 100/image.getWidth(); 
double yScale = 300/image.getHeight(); 
double theScale = xScale > yScale ? xScale : yScale; 

AffineTransform transform = new AffineTransform(); 
transform.setToScale(theScale , theScale); 
//paint code goes here 

这只是一个建议,但,希望它帮助。

+0

非常感谢你...我也用AffineTransformOp过滤图像..thx – user576914 2011-04-01 17:33:15

1

THX计算因子的基于变换的图像宽度/高度相对于目标宽度/高度上。

编写一些代码,如果遇到问题,请提出具体问题。