2013-10-30 76 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解码在这里和服务器端字符串一样。 –