【发布时间】:2014-10-15 08:35:27
【问题描述】:
正在从服务器端向我发送图像。 我以字符串形式接收的图像,服务器端发送给我的是整个文件。 android端怎么读?
File tempFile = File.createTempFile("image", ".jpg", null);
// tempFile.wr
byte[] bytes = output.toString().getBytes();
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(bytes);
输出是我收到的结果,它的字符串是从服务器端发送的整个文件。
Bitmap myBitmap = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
m2.setImageBitmap(myBitmap);
我得到 SkImageDecoder::Factory 返回 null
此代码运行产生此日志猫
File tempFile = File.createTempFile("image", ".jpg", null);
FileOutputStream fos = new FileOutputStream(tempFile);
fos.write(output.toString().getBytes());
fos.close();
System.out.println(""+tempFile.getAbsolutePath());
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither = true;
myOptions.inScaled = false;
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;// important
myOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(tempFile.getAbsolutePath());
m2.setImageBitmap(bitmap);
【问题讨论】:
-
是 base64 还是其他格式?
-
是的,它实际上是一个文件。我得到的输出是一个文件。
-
如果我这样做字节 [] encodeByte=Base64.decode(output.toString(),Base64.DEFAULT);我得到错误的 base 64 作为错误
-
在你的代码中使用这个 base64 类并遵循解码器和编码器的方法。它会工作stackoverflow.com/a/22601645/964741
-
如何下载文件?你使用哪个库?你能显示更多代码吗?