图像不是使用 BitmapFactory.decodeByteArray 创建的 [英] Image isn't creating using the BitmapFactory.decodeByteArray
问题描述
当我将这些字节保存在 txt 文件中并将其另存为 png 文件时,它会显示图像,但它在这里不起作用,为什么...?
When I save those bytes in the txt file and when I save it as png file , it shows the image, but it is not working here why...?
我正在使用此代码从字节数组创建图像在 doInBackground() 上
I am using this code to create image from byte array on 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
and onPostExecute
if(jsondata!=null) {
receiveData(jsondata);
}
logcat 中没有错误,即使其中也没有异常......但图像没有显示.我也做过这样的
There is no error in the logcat, even there is no exception in it..but the image isn't showing. I have also did like this
String data=(String)object;
data=data.trim();
byte[] base64converted=Base64.decode(data,Base64.DEFAULT);
ImageView image=new ImageView(context);
image.setImageBitmap(bmp);
setContentView(image);
但结果相同的图像没有显示但没有异常或错误,这是什么问题...
but the result same image isn't showing but there is no exception or an error, what is the problem...
注释行是当我尝试将这些字节存储到文本文件中时,当我拉出文件时,它会使用 Windows 默认图像查看器显示图像.
The commented lines are when I try to store those bytes into text file and when I pull the file, it shows the images with windows default image viewer.
推荐答案
在从不同资源获取位图时尝试此代码...
Try this code while getting bitmap from different resources...
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);
按照此链接上的教程显示位图的有效方法
这篇关于图像不是使用 BitmapFactory.decodeByteArray 创建的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!