Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AffineTransform API:使用?将图像缩放到最大300*100像素?_Java_2d_Affinetransform - Fatal编程技术网

Java AffineTransform API:使用?将图像缩放到最大300*100像素?

Java AffineTransform API:使用?将图像缩放到最大300*100像素?,java,2d,affinetransform,Java,2d,Affinetransform,我知道如何进行简单的缩放,但如何将图像缩放到最大300*100像素?我搜索了AffineTransform API类,但找不到该类的方法 thx预先根据图像宽度/高度相对于目标宽度/高度计算变换系数 写一些代码,如果遇到问题,可以问一个特定的问题。我想你需要“回到”你的比例因子,通过计算什么比例可以使你的高度达到300像素,宽度达到100 差不多 double xScale = 100/image.getWidth(); double yScale = 300/image.getHeight()

我知道如何进行简单的缩放,但如何将图像缩放到最大300*100像素?我搜索了AffineTransform API类,但找不到该类的方法


thx预先

根据图像宽度/高度相对于目标宽度/高度计算变换系数

写一些代码,如果遇到问题,可以问一个特定的问题。

我想你需要“回到”你的比例因子,通过计算什么比例可以使你的高度达到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

不过,这只是一个建议,希望能有所帮助。

非常感谢……我还使用了AffineTransformOp对图像进行过滤..thx