2011-03-28 14 views
5

क्या मैं बिटमैप को स्ट्रिंग में परिवर्तित कर सकता हूं? और फिर स्ट्रिंग को वापस बिटमैप में परिवर्तित करें?बिटमैप को स्ट्रिंग में कनवर्ट करें

अग्रिम धन्यवाद।

इससे पता चलता है दोनों कैसे करना है:

+0

इस उत्तर पढ़ें: http://stackoverflow.com/questions/4041849/string-to-bitmap-java-android [एंड्रॉयड कोड के – Adnan

+0

संभव डुप्लिकेट करने के लिए बेस 64 स्ट्रिंग कन्वर्ट करने के लिए बिटमैप] (http://stackoverflow.com/questions/3801760/android-code-to-convert-base64-string-to-bitmap) –

+0

http://stackoverflow.com/questions/4837110/how-to के संभावित डुप्लिकेट -convert-a-base64-string-in-a-bitmap-image-to-show-it-in-a-imageview –

उत्तर

3

This कोड क्या आप एक स्ट्रिंग के लिए कनवर्ट करना चाहते हैं प्रतीत होता है How to convert a Base64 string into a BitMap image to show it in a ImageView?

और यह एक एक .bmp वापस करने के लिए परिवर्तित शो: Android code to convert base64 string to bitmap

Google आपका मित्र है ... अगर आपको पहले जवाब पता है तो आपको हमेशा अपने दोस्तों से पूछना चाहिए :)

स्टीव

0

किसी भी फ़ाइल स्वरूप

public String photoEncode(File file){ 
     try{ 

      byte[] byteArray = null; 

      BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file)); 
      ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
      byte[] b = new byte[1024*8]; 
      int bytesRead =0; 

      while ((bytesRead = bufferedInputStream.read(b)) != -1) 
      { 
       bos.write(b, 0, bytesRead); 
      } 

      byteArray = bos.toByteArray(); 
      bos.flush(); 
      bos.close(); 
      bos = null; 

      return changeBytetoHexString(byteArray); 

     }catch(Exception ex){   
      ex.printStackTrace(); 
      return null; 
     } 
    } 

    private String changeBytetoHexString(byte[] buf){ 


     char[] chars = new char[2 * buf.length]; 
     for (int i = 0; i < buf.length; ++i) 
     { 
      chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4]; 
      chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F]; 
     } 
     return new String(chars); 
    } 
संबंधित मुद्दे