图像不是使用BitmapFactory.decodeByteArray创建的
编辑:当我在txt文件中保存这些字节时,当我将其保存为png文件时,它会显示图像,但它在这里不起作用为什么……?
我正在使用此代码从doInBackground()上的字节数组创建图像
String base64data=StringEscapeUtils.unescapeJava(IOUtils.toString(resp.getEntity().getContent())); base64data=base64data.substring(1,base64data.length()-1); JSONObject obj=new JSONObject(base64data); JSONArray array=obj.getJSONArray("EMRTable"); JSONObject childobj=array.getJSONObject(0); results=childobj.getString("DocumentInternalFormat");
和onPostExecute
if(jsondata!=null) { receiveData(jsondata); }
logcat中没有错误,即使它没有exception..但图像没有显示。 我也是这样做的
String data=(String)object; data=data.trim(); byte[] base64converted=Base64.decode(data,Base64.DEFAULT); ImageView image=new ImageView(context); image.setImageBitmap(bmp); setContentView(image);
但结果相同的图像没有显示,但没有exception或错误,问题是什么…
注释行是当我尝试将这些字节存储到文本文件中时,当我拉动文件时,它会显示带有Windows默认图像查看器的图像。
从不同的资源获取位图时尝试此代码…
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(base64converted,0,base64converted.length,options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, 500, 500); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; Bitmap bmp1=BitmapFactory.decodeByteArray(base64converted,0,base64converted.length,options);
按照此链接上的教程显示位图的有效方法
从代码中删除以下行,然后重试
base64data=base64data.substring(1,base64data.length()-1);
- 将位图加载到canvas并在其上绘制
- 如何读取另一个应用程序的数据库
- Trilateration方法Android Java
- 尝试将解析集成到Android应用程序错误时出错:错误:任务执行失败’:app:transformClassesWithDexForDebug’
- android DialogFragment android:onClick =“buttonCancel”导致IllegalStateException无法找到方法
- 对于具有GSON的字段,没有特定结构的Parse JSON
- 为Cloud Endpoints类生成API元数据失败
- Android:进度条将对象上传到服务器
- 如何将数据/参数传递给Android中的另一个活动