Java:ImageIcon 与图像差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11195864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java: ImageIcon vs. Image difference
提问by ps-aux
Could anyone explain to me in noob way what the difference is betweeen ImageIconand Imageclasses/objects in Java? Thanks
谁能以菜鸟的方式向我解释Java 中ImageIcon和Image类/对象之间的区别?谢谢
采纳答案by tenorsax
Their nature and application is different. Imageis an abstract superclass of all classes that represent graphical images. ImageIconis an implementation of Icon
interface that uses Image
as its source.
它们的性质和应用是不同的。Image是所有表示图形图像的类的抽象超类。ImageIcon是用作其源的Icon
接口的实现Image
。
Edit: Think of an Image
as something that couldbe rendered and an ImageIcon
as something that willbe rendered as an Icon
when its paintIcon()
method is called.
编辑:一个想象Image
的东西,可能会被渲染和ImageIcon
为一些将要呈现为Icon
当其paintIcon()
方法被调用。
Edit: The links above will take you to the JDK 6 api. These links will take you to the JDK 8 api: Imageand ImageIcon.
回答by Nicolas
You can scale and save Image, but you can't do it with ImageIcon. For creating pictures in your GUI you usually have to use ImageIcon, but if you don't wanna do that, Image should be better.
您可以缩放和保存 Image,但不能使用 ImageIcon 来完成。要在 GUI 中创建图片,您通常必须使用 ImageIcon,但如果您不想这样做,Image 应该会更好。