图像未创建使用BitmapFactory.de codeByteArray图像、BitmapFactory、codeByteArray、de

2023-09-07 12:51:20 作者:别把玩笑当诺言

编辑: 当我保存这些字节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(图像);
 
肌肤之味Le Gout de Peau 用香气带你 旅行世界

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

注释行是当我尝试这些字节保存成文本文件,当我拉的文件,它显示了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">高效的方式来显示位图