Java是否与图像有任何已知问题并显示它们 [英] Does Java have any known issues with Images and displaying them

查看:130
本文介绍了Java是否与图像有任何已知问题并显示它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java新手,但不是图形新手
我正在尝试扩展我对一个项目的理解,在这个项目中,我使用JLabels和图标显示许多项目照片,以显示它们,

I am new to Java but not new to graphics I'm trying to expand my understanding with a project in which I'm displaying many photos of items using JLabels and Icons to display them,

物品图片从网上的不同位置和许多来源获得。

The items pictures are garnished from various locations on the net and so many sources.

我已将这些图片转换为PNG文件因为他们有透明的背景。

I've converted these into PNG files as they have transparent backgrounds to them.

最近我浪费了整整一个周末检查并重新检查一些代码,因为一个项目根本不会显示,遵循逻辑它的结论告诉我,这个文件有问题,即使文件在photoshop中显示正确吗?

Thing is I wasted a whole weekend recently checking and re-checking some code because one item just would not display, following the logic to its conclusion told me it was the file that was at fault, even though the file displayed correctly in photoshop?

我进入文件查看它的独特之处,但除了8位而不是32位之外,我找不到任何区别。

I went into the file to see what was unique about it, but apart from being 8 bit instead of 32 bit there was no difference I could find.

...所以我的问题是,Java是否有显示任何特定问题的问题在实际查找之前我可能应该知道的文件格式类型克服困难。

...and so to my question, does Java have problems with displaying any particular types of file formats that perhaps I should know prior to actually finding out the hard way.

很抱歉没有代码,因为问题不能保证。

Sorry for no code as the question does not warrant it.

我认为引起我问题的文件是从这里提取的。
http:/ /upload.wikimedia.org/wikipedia/en/d/d5/XXXX_Logo.png

I think the file that caused me problems was pulled from here http://upload.wikimedia.org/wikipedia/en/d/d5/XXXX_Logo.png

推荐答案

至于我理解,Java应该能够处理PNG就好了。 Java不支持的一些格式,包括SVG等矢量图像格式。但是对于大多数这些,有外部库可以提供帮助。

As far as I understand it, Java should be able to handle PNG just fine. There are some formats that Java doesn't support including vector image formats such as SVG. But for most of these, there are outside libraries that can help.

关于您链接到的图像示例,,我没有问题让Java阅读并显示它:

With regards to the image example that you've linked to, , I have no problem getting Java to read and display it:

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Foo {

   public static void main(String[] args) {
      String spec = "http://upload.wikimedia.org/wikipedia/"
            + "en/d/d5/XXXX_Logo.png";
      URL url;
      try {
         url = new URL(spec);
         BufferedImage img = ImageIO.read(url);
         ImageIcon icon = new ImageIcon(img);
         JOptionPane.showMessageDialog(null, icon);
      } catch (MalformedURLException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }     
}

关于你的陈述,


很抱歉没有代码,因为问题不能保证。

Sorry for no code as the question does not warrant it.

我不同意。我认为显示代码并引用导致问题的违规图像是解决问题的关键,例如,如果我的答案对您没有帮助,我强烈建议您告诉我们什么是不合适的方式我们可以重现,类似于我上面发布的代码。

I beg to differ. I think that showing code and a reference to the offending image that causes your problem is key towards solving it, and for example if my answer doesn't help you, I strongly urge you to show us just what isn't working in a way that we can reproduce, similar to the code I've posted above.

这篇关于Java是否与图像有任何已知问题并显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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