android 加载超大图片内存溢出问题
2016-05-06 12:10
471 查看
1.先把图片资源转换成输入流
LargeImageView largeImageView = (LargeImageView) findViewById(R.id.liv); InputStream inputStream = getResources().openRawResource(R.raw.register_background); largeImageView.setInputStream(inputStream);
2.使用
private static final BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
/** * 绘制的区域 */ private volatile Rect mRect = new Rect();
//默认直接显示图片的中心区域,可以自己去调节mRect.left = 0;mRect.top = imageHeight / 2 - height / 2;mRect.right = width;mRect.bottom = mRect.top + height;
public void setInputStream(InputStream is) {try {
BitmapRegionDecoder mDecoder = BitmapRegionDecoder.newInstance(is, false);BitmapFactory.Options tmpOptions = new BitmapFactory.Options();// Grab the bounds for the scene dimensionstmpOptions.inJustDecodeBounds = true;BitmapFactory.decodeStream(is, null, tmpOptions);mImageWidth = tmpOptions.outWidth;mImageHeight = tmpOptions.outHeight;
Bitmap bm = mDecoder.decodeRegion(mRect, options);//修改mRect的边界值即可动态的展示图片区域
} catch (IOException e) {e.printStackTrace();} finally {try {if (is != null) is.close();} catch (Exception e) {}}}
相关文章推荐
- Android API中被@hide注释的方法引用报错解决
- Android数据库事务浅析
- Android Studio教程从入门到精通
- Android自定义控件进阶篇(一)
- Android Design Support Library初探,NavigationView实践
- android Service 的简单使用
- LayoutInflater的简单认识
- Android采用双缓冲技术实现画板
- Android Studio点击运行按钮找不到虚拟机
- EventBus 3.0 使用详解
- android5.0 如何开启wif热点
- Android通过手势实现答题器翻页效果
- Android读写文件 获取文件并读取写入数据
- Android Dev Intro - Introducing GLSurfaceView
- Android开发-API指南-<activity-alias>
- Android中Service(服务)详解
- ASM (Android Screen Monitor) Android真机抓屏
- Retrofit 的使用详解(下载 多文件上传)
- Android学习之----利用DownLoadManager实现版本升级
- 【Android基础】Android跳转浏览器打开URL