图像未创建使用BitmapFactory

图像未创建使用BitmapFactory

本文介绍了图像未创建使用BitmapFactory.de codeByteArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

编辑:当我保存这些字节txt文件,当我把它保存为PNG文件时,它显示的图像,但它不能在这里工作,为什么......?

我用这code,创建从字节数组图像在doInBackground()

 字符串base64data = StringEscapeUtils.unescapeJava(IOUtils.toString(resp.getEntity()的getContent()));
             base64data = base64data.substring(1,base64data.length() -  1);
             JSONObject的OBJ =新的JSONObject(base64data);
             JSONArray阵列= obj.getJSONArray(EMRTable);
             的JSONObject childobj = array.getJSONObject(0);
             结果= childobj.getString(DocumentInternalFormat);
 

和onPostExecute

 如果(jsondata!= NULL)
     {
         receiveData(jsondata);
     }
 

有一个在logcat中没有出现错误,即使存在在it..but也不例外的图像没有显示。我也做了这样的

 字符串数据=(字符串)对象;
                数据= data.trim();
                byte []的base64converted = Base64.de code(数据,Base64.DEFAULT);
//
                BMP位= BitmapFactory.de codeByteArray(base64converted,0,base64converted.length);
//文件根= android.os.Environment.getExternalStorageDirectory();
//文件DIR =新的文件(root.getAbsolutePath()+/下载);
//档案文件=新的文件(目录,姓名);
// FileOutputStream中F =新的FileOutputStream(文件);
// f.write(base64converted);
// f.flush();

                ImageView的形象=新ImageView的(上下文);
                image.setImageBitmap(BMP);
                的setContentView(图像);
 

但结果相同的图像无法显示,但没有异常或错误,这是什么问题...

注释行是当我尝试这些字节保存成文本文件,当我拉的文件,它显示了Windows默认的图像浏览器中的图像。

解决方案

试试这个code,同时获得来自不同资源的位图...

  BitmapFactory.Options选项=新BitmapFactory.Options();
            options.inJustDe codeBounds = TRUE;
            BitmapFactory.de codeByteArray(base64converted,0,base64converted.length,期权);

            //计算inSampleSize
            options.inSampleSize = calculateInSampleSize(选项,500,500);
            与inSampleSize集//德code位图
            options.inJustDe codeBounds = FALSE;
            位图BMP1 = BitmapFactory.de codeByteArray(base64converted,0,base64converted.length,期权);
 

遵循href="http://developer.android.com/training/displaying-bitmaps/index.html" rel="nofollow">高效的方式来显示位图

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 arrayon 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);
//
                Bitmap bmp=BitmapFactory.decodeByteArray(base64converted,0,base64converted.length);
//                File root = android.os.Environment.getExternalStorageDirectory();
//                File dir = new File (root.getAbsolutePath() + "/download");
//                  File file = new File(dir, "name");
//                  FileOutputStream f = new FileOutputStream(file);
//                 f.write(base64converted);
//                 f.flush();

                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.

解决方案

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

这篇关于图像未创建使用BitmapFactory.de codeByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 17:26