2013-10-30 79 views
0

在我的android應用程序中,我想將圖像轉換爲字節並對其進行編碼。併發送到數據庫。但是當我將其轉換回圖像時,它不顯示。請help.and告訴我在哪裏我就在服務器端犯錯誤當轉換回圖像時轉換爲字節的圖像

final Bitmap image=(images.get(position)); 



       int size = image.getRowBytes() * image.getHeight(); 



       ByteBuffer buffer = ByteBuffer.allocate(size); //Create a new buffer 
       image.copyPixelsToBuffer(buffer); //Move the byte data to the buffer 

       byte[] array = buffer.array(); 

       encodedImageString = Base64.encodeToString(array, Base64.DEFAULT); 

現在,當我解碼此編碼和imagestring寫它,它不顯示圖像。

      Byte[] imageByteArary= base64.decode(encodedImageString); 
          File myfile=new File("D://test1.jpg"); 
      myfile.createNewFile(); 
      FileOutputStream fOut=new FileOutputStream (myfile); 
      fOut.write(imageByteArray); 
      fOut.close(); 
+1

'copyPixelsToBuffer()'不會創建一個JPEG格式。 – SLaks

回答

0

我面臨的是你從客戶端發送相同的problem.The字符串不是同樣會收到在服務器端的東西。

Check this for solution

+0

我找不到解決方案。請幫忙 – user2768215

+0

最好的方法是在發送到服務器之前捕獲字符串並捕獲服務器收到的字符串,然後比較兩者。你會找到你的解決方案。在我的情況下,如果我們輸入了字符串,它就會到達下一行,但是當它被髮送到服務器時,它被添加了「\ n」。檢查兩個字符串之間的區別,我說你並讓我知道區別 –

+0

在客戶端捕獲編碼的字符串和http://www.freeformatter.com/base64-encoder.html解碼在這裏和服務器端字符串一樣。 –