栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android:位图到字节数组并返回:SkImageDecoder :: Factory返回null

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android:位图到字节数组并返回:SkImageDecoder :: Factory返回null

您正在将位图传递到Intent中,并从捆绑包中的下一个活动中获取位图,但是问题在于,如果那时您的位图/图像大小很大,则无法在下一个活动中加载图像。

使用以下2个解决方案来解决此问题。

1)首先将图像转换为字节数组,然后传递到Intent,然后在下一个活动中从Bundle中获取字节数组,然后转换为Image(Bitmap)并设置为ImageView。

将位图转换为字节数组:

Bitmap bmp = BitmapFactory.depreResource(getResources(), R.drawable.ic_launcher);ByteArrayOutputStream stream = new ByteArrayOutputStream();bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);byte[] byteArray = stream.toByteArray();

将字节数组传递给意图:

Intent intent = new Intent(this, NextActivity.class);intent.putExtra("picture", byteArray);startActivity(intent);

从捆绑中获取字节数组并转换为位图图像:-

Bundle extras = getIntent().getExtras();byte[] byteArray = extras.getByteArray("picture");Bitmap bmp = BitmapFactory.depreByteArray(byteArray, 0, byteArray.length);ImageView image = (ImageView) findViewById(R.id.imageView1);image.setImageBitmap(bmp);

2)首先将图像保存到SDCard中,然后在下一个活动中将此图像设置为ImageView。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/609600.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号