gpt4 book ai didi

java - 图像不是使用 BitmapFactory.decodeByteArray 创建的

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:47:54 27 4
gpt4 key购买 nike

编辑:当我将这些字节保存在 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 中没有错误,即使其中没​​有异常..但是图像没有显示。我也这样做过

String data=(String)object;
data=data.trim();
byte[] base64converted=Base64.decode(data,Base64.DEFAULT);

ImageView image=new ImageView(context);
image.setImageBitmap(bmp);
setContentView(image);

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

注释行是当我尝试将这些字节存储到文本文件中时,当我拉取文件时,它会使用 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);

按照此链接上的教程 Efficient way to show bitmaps

关于java - 图像不是使用 BitmapFactory.decodeByteArray 创建的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14681643/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com