Java选择:以JAR或Base64顺序存储图像?

时间:2012-02-20 10:43:46

标签: java jar base64 imageicon

我写了一个扑克模拟器/赔率计算器。在GUI上,有一些JComboBox es,用户可以从中选择卡片。

现在,我有这些卡的图像,我也有Base64格式的图像。我试图通过3种不同的方式显示它们。为了演示目的,我为每个人写了一个小程序。

以下是我尝试的3种方法:

1)。将图像存储在JAR文件中:

非常简单。图像进入JAR,Java代码从那里读取它们。之后,它会创建一个包含所有这些内容的JComboBox并显示它:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;

public class ImagesFromJAR
{
    private JFrame mainframe;

    public ImagesFromJAR ()
    {
        ImageIcon[] cardslist = new ImageIcon[52];

        for (int i = 0; i < 52; ++i)
        {
            cardslist[i] = new ImageIcon (getClass (). getResource ((this.getImagePath (i))));
        }

        JComboBox cardsbox = new JComboBox (cardslist);
        cardsbox.setSelectedIndex (0);
        cardsbox.setEditable (false);

        this.mainframe = new JFrame ();
        this.mainframe.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
        this.mainframe.setSize (150, 150);
        this.mainframe.setLayout (null);

        cardsbox.setBounds (20, 20, 55, 45);
        this.mainframe.add (cardsbox);

        this.mainframe.setVisible (true);
    }

    private String getImagePath (int index)
    {
        switch (index)
        {
            case 0: return "images/2c.gif";
            case 1: return "images/3c.gif";
            case 2: return "images/4c.gif";
            case 3: return "images/5c.gif";
            case 4: return "images/6c.gif";
            case 5: return "images/7c.gif";
            case 6: return "images/8c.gif";
            case 7: return "images/9c.gif";
            case 8: return "images/Tc.gif";
            case 9: return "images/Jc.gif";
            case 10: return "images/Qc.gif";
            case 11: return "images/Kc.gif";
            case 12: return "images/Ac.gif";
            case 13: return "images/2d.gif";
            case 14: return "images/3d.gif";
            case 15: return "images/4d.gif";
            ......................................
            default: return null;
        }
    }

    public static void main (String[] args)
    {
        javax.swing.SwingUtilities.invokeLater (new Runnable ()
        {
            public void run ()
            {
                ImagesFromJAR t = new ImagesFromJAR ();
            }
        });
    }
}

2)。将图像以Base64格式存储在文本文件中:

我以Base64格式转换每个图像,然后存储在文本文件中。 Java代码读取该文件并通过解码文件中的行来重新创建图像。之后,创建并显示JComboBox

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.IOException;

public class CodeFromFile
{
    private JFrame mainframe;

    public CodeFromFile ()
    {
        ImageIcon[] cardslist = new ImageIcon[52];

        InputStreamReader in = null;
        BufferedReader buff;

        int index = -1;

        try
        {
            in = new InputStreamReader (new FileInputStream ("card.encodings.txt"));
            buff = new BufferedReader (in);

            String line;
            byte[] ba;

            while ((line = buff.readLine ()) != null)
            {
                if (line.length () < 10)
                {
                    continue;
                }

                index++;

                ba = Base64.decode (line);

                cardslist[index] = new ImageIcon (ba);
            }
        }
        catch (IOException e)
        {
            e.printStackTrace ();
        }
        finally
        {
            if (in != null)
            {
                try
                {
                    in.close ();
                }
                catch (IOException e2) {}
            }
        }

        JComboBox cardsbox = new JComboBox (cardslist);
        cardsbox.setSelectedIndex (0);
        cardsbox.setEditable (false);

        this.mainframe = new JFrame ();
        this.mainframe.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
        this.mainframe.setSize (150, 150);
        this.mainframe.setLayout (null);

        cardsbox.setBounds (20, 20, 55, 45);
        this.mainframe.add (cardsbox);

        this.mainframe.setVisible (true);
    }

    public static void main (String[] args)
    {
        javax.swing.SwingUtilities.invokeLater (new Runnable ()
        {
            public void run ()
            {
                CodeFromFile t = new CodeFromFile ();
            }
        });
    }
}

card.encodings.txt的内容是这样的:

2c:
R0lGODlhHgAmAMQAAAAAAP///+7u7t3d3czMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABAALAAAA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oxs0w1ZDOIdhan0Al3iMbZeQZEhEAOw==
5c:
R0lGODlhHgAmALMAAAAAAP///+7u7szMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///yH5BAEAAA8ALAAAAAAeACYAAATA8D1Aq734yhm6/2AIApxonh6FrqLKvp2LGg7ADKtsGpYjoDrR4nIAAlY1i8K4ahCZogSgobhUHYbWMYTIYAqhYCfprSTCWxC5MrycR+nP4YIwtCsEtGk+NQgWAXwMYHosVUU5cSIIdwqIJmIeXV6EhTAskZeWmieZnCmKJgwVS52hIQQWWaaGj4krAwAOCD+vKFIUDpWQpyEHQz5QL12umywMpbyaCAjCLzfOizgBjrYnbQu7yp+dJdwjG2XiGRIRADs=

..它会继续为每张图片/卡片。

3)。第三种方法是将图像直接存储在Base64 String中的源代码中。像这样:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.ImageIcon;

public class CodeFromSource
{
    private JFrame mainframe;

    public CodeFromSource ()
    {
        ImageIcon[] cardslist = new ImageIcon[52];

        byte[] ba;

        for (int i = 0; i < 52; ++i)
        {
            ba = Base64.decode (this.getImageCode (i));
            cardslist[i] = new ImageIcon (ba);
        }

        JComboBox cardsbox = new JComboBox (cardslist);
        cardsbox.setSelectedIndex (0);
        cardsbox.setEditable (false);

        this.mainframe = new JFrame ();
        this.mainframe.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE);
        this.mainframe.setSize (150, 150);
        this.mainframe.setLayout (null);

        cardsbox.setBounds (20, 20, 55, 45);
        this.mainframe.add (cardsbox);

        this.mainframe.setVisible (true);
    }

    private String getImageCode (int index)
    {
        switch (index)
        {
            case 0: return "R0lGODlhHgAmAMQAAAAAAP///+7u7t3d3czMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABAALAAAAAAeACYA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Mcoxs0w1ZDOIdhan0Al3iMbZeQZEhEAOw==";
            case 3: return "R0lGODlhHgAmALMAAAAAAP///+7u7szMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///yH5BAEAAA8ALAAAAAAeACYAAATA8D1Aq734yhm6/2AIApxonh6FrqLKvp2LGg7ADKtsGpYjoDrR4nIAAlY1i8K4ahCZogSgobhUHYbWMYTIYAqhYCfprSTCWxC5MrycR+nP4YIwtCsEtGk+NQgWAXwMYHosVUU5cSIIdwqIJmIeXV6EhTAskZeWmieZnCmKJgwVS52hIQQWWaaGj4krAwAOCD+vKFIUDpWQpyEHQz5QL12umywMpbyaCAjCLzfOizgBjrYnbQu7yp+dJdwjG2XiGRIRADs=";
            case 4: return "R0lGODlhHgAmAMQAAAAAAP///+7u7t3d3czMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABAALAAAAAAeACYAAAXZIAQBZGme6CmOQeu+cAwDrGzfLonvss7/LR/u8AA0CDuh7WB6CHBKGeOEgAJ2RdPCunNQuTIFwLE4lR+H3jWWSKEMsWgr6y4p4msYvTQ93Wd5LwgnCQd9JQV4NoNjBwIMAYwNcIo8ZVVJgTIJhwuYNnIubW6UlUA8oaemqjeprDmaNwNiAE+gsTJMDKW3PExpqLgvAw+fmTsLD6MMtr04DwxITA1gNgQAn2KJztbYLky8gDgD3i0GANtqOw0O3w/VNgUAdwQOwNw3Bl5ox6+tNf5mrKhDMIWIEAA7";
            case 5: return "R0lGODlhHgAmAMQAAAAAAP///+7u7t3d3czMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABAALAAAAAAeACYAAAXGIAQBZGme6CmOQeu+cAwDrG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CA4DAWJIrbF6aS0OkL44BQClbbqgvy4GyC6DvWrGAH+RANOrMg3QBAwPYDePJLhbxUAGD8vMQAQOn+07A23B4jICJArs969xNf5mrKhDMIWIEAA7";
            case 8: return "R0lGODlhHgAmAMQAAAAAAP///+7u7t3d3czMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABAALAAAAAAeACYAAAX4IAQBZGme6CmOQeu+cAwDrGzfLonvss7/LR/u8AA0CDuh7WB6CHBKGeOEgAJ2RdPCunNQuTIFwLE4lR+H3jWWSKEMsWgr6y4p4msYvTQ93Wd5LwgnCQd9JQV4NoNjBwIMAYwNcIo8ZVVJgTIJhwuYNnIubW6UlUA8oaemqjeprDmaLgIJDp8BBA1GSKsvDkWfAw9VCA8DvC8FAJ8LDS4NW4A3BMouwi7Exy7TmMlpLUyJL67bLQYApealQbHa1AHpLvDi7C3kAd0u4NE29gHWLdj2yejHzBm0eTeSAbNGzJhAGGVINKuXi8Guh6/i1Mg4Y0WdjylEhAAAOw==";
            case 9: return "R0lGODlhHgAmALMAAAAAAP///+7u7szMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///yH5BAEAAA8ALAAAAAAeACYAAAS38D1Aq734yhm6/2AIApxonh6FrqLKvp2LGg7ADKtsGpYjoDrR4nIAAlY1i8K4ahCZogSgobhUHYbWMYTIYAqhYCfprSTCWxC5MrycR+nP4YIwtCsEtGk+NQgWAXwMYHosVUU5cSIIdwqIJmIeXV6EhTAskZeWmieZnCmKIQM9iS9deaUsczipK6uYoSKvrSizUK4ArLe1ubAvtp2xIQcOL54BVQQIb7TDFEvGwp8xJdMjG2XZGRIRADs=";
            case 10: return "R0lGODlhHgAmAMQAAAAAAP///+7u7t3d3czMzLu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREf///wAAAA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gobhUHYbWMYTIYAqhYCfprSTCWxC5MrycR+nP4YIwtCsEtGk+NQgWAXwMYHosVUU5cSIIdwqIJmIeXV6EhTAskZeWmieZnCmKJgMAeYkvVW9QKAIODD6mKwcIc4+QoSENA6wMsCcFgAFVOJ23H4MdBQAIqiKjFw3MIQm1XZWbIKw/HqNLticL3cYAtR+ZSQ4fZLzXnyMl7e4SZfMZEhEAOw==";
            case 13: return "R0lGODlhHgAmAMQAAAAAAP////8AAP8REf8iIv8zM/9ERP9VVf9mZv93d/+IiP+Zmf+qqv+7u//MzP/d3f/u7v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABEALAAAAAAeACYAAAW/YBQBZGme6CmOQeu+cAwDrGzfLonvss4HiJ9vtxAkeMMbhCAQNHZJm6EpIEBw0ZiC2gzesq8Gl7r4ApTMcfPZO9sOairBBm4t40662yZWK8w7W1wGWHs3U01WhTx3eYs8DAJejzwJV1CGP5iamnWcM5kxD4gGDps4BQwBDgQDl3o4C6YtkX+AmhACtrCaD468PwqElDtLD6c8BmzENwllSKExCbsJx8A2CWNzt9hqk22f0OFQNeMxNCIp6uskIiEAOw==";
            .........
            default: return null;
        }
    }

    public static void main (String[] args)
    {
        javax.swing.SwingUtilities.invokeLater (new Runnable ()
        {
            public void run ()
            {
                CodeFromSource t = new CodeFromSource ();
            }
        });
    }
}

(我必须删除一些交换机案例,因为StackOverflow上有30 K字符限制)

这些方法中的每一个都产生相同的结果,即:

Result

PS:Base64类只是一些编码/解码Base64信息的实用程序类(你可以在下面的链接中找到它。)

如果您需要所有资源(图片,源代码等),您可以从这里获取它们:Resources

现在我们清除了......我想要的是知道这三种方法中的哪一种更好。每个人的优点和缺点是什么?我应该使用哪一个?为什么?我也在谈论JAR文件损坏的可能性。

我唯一不关心的是表现。

2 个答案:

答案 0 :(得分:5)

  1. 是首选,因为不涉及转换,您的代码可以从类路径中读取它们。这使您的应用程序自包含。腐败不是问题,因为这会使整个应用程序变得无用 - 不仅仅是图像文件

  2. 将涉及转换(启动时间和内存)的运行时惩罚,alsop引入配置文件。

  3. 与2一样糟糕,但灵活性也较差(如果不重新编译,则无法更改图像)

答案 1 :(得分:2)

将图像放入Jar中是最常见的,因此最容易让其他人使用或回答问题(这可能是也可能不重要)。

我怀疑2或3会产生较小的可分发的结尾。至于腐败的可能性。这似乎适用于Jars中的类或资源,或纯文本文件。那么问题就变成“每个人被破坏的可能性有多大?”我认为答案是“字节越多,机会就越大”。