2011-03-28 10 views
5

Bitmap'i String'e dönüştürebilir miyim? Ve sonra Dizeyi Bitmap'e geri dönüştürün?Bitmap'i Dize Dönüştür

Şimdiden teşekkürler.

Bu iki işlemin nasıl gösterir:

+0

bu cevabı oku: base64 dize dönüştürmek için http://stackoverflow.com/questions/4041849/string-to-bitmap-java-android [Android kod – Adnan

+0

olası yinelenen bitmap] (http://stackoverflow.com/questions/3801760/android-code-to-convert-base64-string-to-bitmap) –

+0

http://stackoverflow.com/questions/4837110/how-to sayfasının olası kopyası -convert-a-base64-string-içine-bir-bitmap-resme-göstermek-in-a-imageview –

cevap

0

herhangi bir dosya biçimi

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); 
    } 
İlgili konular