如何将图像放在masterflow中

时间:2015-04-28 20:32:41

标签: android eclipse

如何将图像放入主/细节流程中。我的程序是这样的:

 addItem(new DummyItem("4", "Slika",
            "http://milos-radic-et4.from.hr/files/2014/10/EM%C5%A0A.jpg"));

 addItem(new DummyItem("5", "E-dnevnik", ""));

 addItem(new DummyItem("6", "Web-stranica", "/"));

 addItem(new DummyItem("7", "Vremenik", ""));

我想将图片添加到

addItem(new DummyItem("4", "Slika", ""));

不是图片的链接。这甚至可能吗?

1 个答案:

答案 0 :(得分:0)

从URL中读取图像并将其转换为字符串,如下所示

File file = new File("/Users/iqbal/Pictures/wallpapers/water-drop.jpg");

        try {           
            // Reading a Image file from file system
            FileInputStream imageInFile = new FileInputStream(file);
            byte imageData[] = new byte[(int) file.length()];
            imageInFile.read(imageData);

            // Converting Image byte array into Base64 String
            String imageDataString = Base64.encodeBase64URLSafeString(imageData);
          imageInFile.close();

        } catch (FileNotFoundException e) {
            System.out.println("Image not found" + e);
        } catch (IOException ioe) {
            System.out.println("Exception while reading the Image " + ioe);
        }

将字符串转换回图像,如下所示

 try {
    // Converting a Base64 String into Image byte array

    byte[] imageByteArray = Base64.decodeBase64(imageDataString);

    // Write a image byte array into file system
    FileOutputStream imageOutFile = new FileOutputStream(
            "/Users/iqbal/Pictures/wallpapers/water-drop-after-convert.jpg");

    imageOutFile.write(imageByteArray);

    imageOutFile.close();

   } catch (FileNotFoundException e) {
        System.out.println("Image not found" + e);
    } catch (IOException ioe) {
        System.out.println("Exception while reading the Image " + ioe);
    }