如何使用 RescaleOp 设置图像大小
我正在编写一个测试应用程序。为了设置图像的Alpha,我使用paintComponent方法。观看下一个片段...
public class TestImage extends JLabel{
public void paintComponent( Graphics g ) {
super.paintComponent( g );
Graphics2D g2d=(Graphics2D)g;
g2d.drawImage(this.bImage, rop, 0, 0);
}
public void setRescaleOp(RescaleOp rop){this.rop=rop;}
}
如您所见,
g2d.drawImage(this.bImage, rop, 0, 0);
不允许设置宽度和高度,就像我使用 g.drawImage(bImage, 0, 0,width,height, null);
所以问题是...在这种情况下如何设置 bImage 的宽度和高度?
任何有用的评论表示赞赏
安德鲁
I am writing a test app. To set Alpha for image I use paintComponent method. Watch next snippet...
public class TestImage extends JLabel{
public void paintComponent( Graphics g ) {
super.paintComponent( g );
Graphics2D g2d=(Graphics2D)g;
g2d.drawImage(this.bImage, rop, 0, 0);
}
public void setRescaleOp(RescaleOp rop){this.rop=rop;}
}
As you can see,
g2d.drawImage(this.bImage, rop, 0, 0);
does not allow to set width and height as if I use g.drawImage(bImage, 0, 0,width,height, null);
So the question is... How to set width and height for bImage in this case?
Any useful comment is appreciated
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先
filter()
,如图此处,然后使用drawImage()
进行缩放或AffineTransformOp
,如此处所示。附录:或者,您可以先缩放图像(使用上述任一方法),然后使用您的
drawImage()
中的RescaleOp
。顺便说一句,
RescaleOp
缩放图像的色带;它不会改变图像的尺寸。为了避免混淆,维度缩放有时被称为重采样。
附录:这是使用
drawImage()
重新采样和RescaleOp
调整图像的 alpha。First
filter()
, as shown here, and then scale usingdrawImage()
orAffineTransformOp
, as shown here.Addendum: Alternatively, you can scale the image first (using either approach above) and then use your
RescaleOp
indrawImage()
.As an aside,
RescaleOp
scales the image's color bands; it does not change the image's dimensions. To avoid confusion, dimensional scaling is sometimes called resampling.Addendum: Here's an example of using
drawImage()
to resample andRescaleOp
to adjust the alpha of an image.