转换列表< BufferedImage>印象 [英] Convert List<BufferedImage> to Image

查看:185
本文介绍了转换列表< BufferedImage>印象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下.ico图像,使用image4j库读取:

I have the following .ico image, read using image4j library:

List<BufferedImage> BI = ICODecoder.read("aImage.ico");

下一步我想将此图像设置为框架图标:

Next I want to set this image as a frame icon:

myFrame.setIconImage((Image)BI);

错误:java.lang.ClassCastException

Error: java.lang.ClassCastException

我需要将类型List< \ BufferedImage>转换为Image类型。任何帮助将不胜感激。

I need to convert the type List<\BufferedImage> to the type Image. Any help would be appreciated.

推荐答案

您可以考虑使用...

You could consider using...

myFrame.setIconImage(BI.get(0));

列表是一个东西列表(或技术上对象 s,在你的情况下, BufferedImage s),其中 setIconImage 只需要一个......

List is a list of stuff (or technically Objects, in your case, BufferedImages), where as setIconImage expects just one...

或者,你可以利用 JFrame 的能力通过使用...提供不同分辨率的多个不同图像。

Alternatively, you could take advantage of of JFrame's capability of providing multiple different images at different resolutions by using...

myFrame.setIconImages(BI);

这可能是你首先想要的......

Which is probably what you were after in the first place...

这篇关于转换列表&lt; BufferedImage&gt;印象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆