[英]Resize Image in Java. How to resize
I am trying to display an image on a Frame, however the image doesn't fit exactly on the frame. 我试图在帧上显示图像,但图像并不完全适合帧。 How can I resize the image?
如何调整图像大小? I cannot resize the frame.
我无法调整框架的大小。 I need it to stay the same size all the time.
我需要它始终保持相同的大小。
// Override paint():
public void paint (Graphics g)
{
Dimension dimension = this.getSize();
Insets I = this.getInsets();
Toolkit tk = Toolkit.getDefaultToolkit();
try{
URL u = new URL ("http://www.gstatic.com/hostedimg/c195c33263b5205c_large");
Image img = tk.getImage(u);
g.drawImage(img, 0+I.left, 0+I.top, this);
}
catch(MalformedURLException e){
System.out.println(e);
}
}
Use one of the drawImage methods, where you can provide the required width and height of the drawing area. 使用drawImage方法之一,您可以在其中提供绘图区域所需的宽度和高度。 Eg:
例如:
g.drawImage(img, 0+I.left, 0+I.top, myWidth, myHeight, this);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.