Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
626 views
in Technique[技术] by (71.8m points)

java - Image isn't creating using the BitmapFactory.decodeByteArray

Edit: 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...?

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");

and onPostExecute

if(jsondata!=null) {
    receiveData(jsondata);
}

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...

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);

follow the tutorial on this link Efficient way to show bitmaps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...