android 手机或平板上加载大图片问题

ccchp 2013-05-31 11:56:47
我SDCard里有一张几十兆或者几百兆的图片 ,我想把他显示出来, 应该如可处理呢? 希望有这方面经验的人能够指点我下(注意是“一张”大的图片)
...全文
311 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
youngplayee 2013-06-09
  • 打赏
  • 举报
回复
虚拟机可用内存很小。所以,可以考虑用jni搞。jni可用内存大得多。在jni里生成bitmap对象后返回。
王端晴 2013-06-07
  • 打赏
  • 举报
回复
BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream( new FileInputStream(new File(path_image)), null, o); int w = o.outWidth; int h = o.outHeight; int scale = 1; while (true) { if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) { break; } w /= 2; h /= 2; scale *= 2; } o.inSampleSize = scale; o.inJustDecodeBounds = false; newBitmap = BitmapFactory.decodeStream( new FileInputStream(new File(path_image)), null, o); 这种方式不会把图片加载到内存中吗,有何依据?
maclay 2013-06-07
  • 打赏
  • 举报
回复
引用 16 楼 ccchp 的回复:
[quote=引用 12 楼 maclay 的回复:]
BitmapFactory.Options o = new BitmapFactory.Options();
					o.inJustDecodeBounds = true;
					 BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
					int w = o.outWidth;
					int h = o.outHeight;
					int scale = 1;
					while (true) {
						if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) {
							break;
						}
						w /= 2;
						h /= 2;
						scale *= 2;
					}
					o.inSampleSize = scale;
					o.inJustDecodeBounds = false;
					 newBitmap = BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
你可以参考一下,这个不会把图片加载到内存中,就可以获取宽和高。
为什么我这 获取bitmap为空 第一次decodeStream时候就是空 文件确实在该路径下[/quote] 你要注意injusetdecodebounds的设置,确定为false才会真正的加载图片到内存。
ccchp 2013-06-05
  • 打赏
  • 举报
回复
引用 12 楼 maclay 的回复:
BitmapFactory.Options o = new BitmapFactory.Options();
					o.inJustDecodeBounds = true;
					 BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
					int w = o.outWidth;
					int h = o.outHeight;
					int scale = 1;
					while (true) {
						if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) {
							break;
						}
						w /= 2;
						h /= 2;
						scale *= 2;
					}
					o.inSampleSize = scale;
					o.inJustDecodeBounds = false;
					 newBitmap = BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
你可以参考一下,这个不会把图片加载到内存中,就可以获取宽和高。
为什么我这 获取bitmap为空 第一次decodeStream时候就是空 文件确实在该路径下
kk1924 2013-06-04
  • 打赏
  • 举报
回复
楼主有这么大的图片显示,真少见,,如果楼主解决了,,,希望分享下经验,,谢谢了
maclay 2013-06-04
  • 打赏
  • 举报
回复
BitmapFactory.Options o = new BitmapFactory.Options();
					o.inJustDecodeBounds = true;
					 BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
					int w = o.outWidth;
					int h = o.outHeight;
					int scale = 1;
					while (true) {
						if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) {
							break;
						}
						w /= 2;
						h /= 2;
						scale *= 2;
					}
					o.inSampleSize = scale;
					o.inJustDecodeBounds = false;
					 newBitmap = BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
你可以参考一下,这个不会把图片加载到内存中,就可以获取宽和高。
ccchp 2013-06-04
  • 打赏
  • 举报
回复
引用 9 楼 mmorss 的回复:
[quote=引用 6 楼 ccchp 的回复:] [quote=引用 3 楼 mmorss 的回复:] 你把那个图发我,我试试看
不好意思 ,回复晚了,可以留个邮箱不,给你发个图[/quote] xpf3@qq.com[/quote] 已发送,请接收
ccchp 2013-06-04
  • 打赏
  • 举报
回复
引用 8 楼 maclay 的回复:
压缩,可以给一个限定值,然后把原图压缩一半,看是否合适,不合适再压缩一次一直到合适为止,大概就是这个思路。以前做过。
本人菜鸟,可以提供个方法吗?我试过的方法都OOM
mmorss 2013-06-04
  • 打赏
  • 举报
回复


public byte[] InputStreamToByte(InputStream iStrm) throws IOException {
		ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
		int ch;
		while ((ch = iStrm.read()) != -1) {
			bytestream.write(ch);
			Log.i("xpf", "as=one writed" + bytestream.size() + " 剩余" + (Filel - bytestream.size()));
		}
		byte imgdata[] = bytestream.toByteArray();
		bytestream.close();
		return imgdata;
	}
s
ccchp 2013-06-04
  • 打赏
  • 举报
回复
引用 12 楼 maclay 的回复:
BitmapFactory.Options o = new BitmapFactory.Options();
					o.inJustDecodeBounds = true;
					 BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
					int w = o.outWidth;
					int h = o.outHeight;
					int scale = 1;
					while (true) {
						if (w / 2 <= mWidth_image || h / 2 <= mWidth_image) {
							break;
						}
						w /= 2;
						h /= 2;
						scale *= 2;
					}
					o.inSampleSize = scale;
					o.inJustDecodeBounds = false;
					 newBitmap = BitmapFactory.decodeStream(
							new FileInputStream(new File(path_image)), null, o);
你可以参考一下,这个不会把图片加载到内存中,就可以获取宽和高。
好的 谢谢
maclay 2013-06-03
  • 打赏
  • 举报
回复
压缩,可以给一个限定值,然后把原图压缩一半,看是否合适,不合适再压缩一次一直到合适为止,大概就是这个思路。以前做过。
u010934091 2013-06-03
  • 打赏
  • 举报
回复
压缩后提取。
ccchp 2013-06-03
  • 打赏
  • 举报
回复
引用 3 楼 mmorss 的回复:
你把那个图发我,我试试看
不好意思 ,回复晚了,可以留个邮箱不,给你发个图
mmorss 2013-06-03
  • 打赏
  • 举报
回复
引用 6 楼 ccchp 的回复:
[quote=引用 3 楼 mmorss 的回复:] 你把那个图发我,我试试看
不好意思 ,回复晚了,可以留个邮箱不,给你发个图[/quote] xpf3@qq.com
DrSmart 2013-05-31
  • 打赏
  • 举报
回复
先缩略图然后再显示
不简单de 2013-05-31
  • 打赏
  • 举报
回复
先生成一个小图再显示
mmorss 2013-05-31
  • 打赏
  • 举报
回复
AVM只会给应用分的内存是固定的,手机才多大内存,操作那么大的图片,都放不下,只能读进来一部分然后操作,然后释放再读下一部分
mmorss 2013-05-31
  • 打赏
  • 举报
回复
你把那个图发我,我试试看
ccchp 2013-05-31
  • 打赏
  • 举报
回复
引用 1 楼 DrSmart 的回复:
先缩略图然后再显示
太笼统了 ,可以详细点儿不。比如一开始获得bitmap对象都会出现内存溢出

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧