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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:10:58  来源:igfitidea点击:

Java: ImageIcon vs. Image difference

javaimageswingawtimageicon

提问by ps-aux

Could anyone explain to me in noob way what the difference is betweeen ImageIconand Imageclasses/objects in Java? Thanks

谁能以菜鸟的方式向我解释Java 中ImageIconImage类/对象之间的区别?谢谢

采纳答案by tenorsax

Their nature and application is different. Imageis an abstract superclass of all classes that represent graphical images. ImageIconis an implementation of Iconinterface that uses Imageas its source.

它们的性质和应用是不同的。Image是所有表示图形图像的类的抽象超类。ImageIcon是用作其源的Icon接口的实现Image

Edit: Think of an Imageas something that couldbe rendered and an ImageIconas something that willbe rendered as an Iconwhen 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.

编辑:上面的链接将带您到 JDK 6 api。这些链接会将您带到 JDK 8 api:ImageImageIcon

回答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 应该会更好。