您的位置:首页 > 移动开发 > Android开发

android显示加载大图片OOM问题

2016-11-03 14:12 435 查看
本人测试1300W像素图像显示和加载到bitmap都会出现OOM,最后在同事的帮助下终于搞清楚解决方法。

显示OOM问题解决方法添加ImageLoader :

//1.创建默认的ImageLoader配置参数 

ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this) 

.writeDebugLogs() //打印log信息 

.build();

   //2.显示图片的配置 

DisplayImageOptions options = new DisplayImageOptions.Builder() 

       .showImageOnLoading(R.drawable.tongue) 

       .showImageOnFail(R.drawable.tongue) 

        .cacheInMemory(true) 

        .bitmapConfig(Bitmap.Config.RGB_565) 

        .build(); 

//3。初始化ImageLoader

ImageLoader imageLoader = ImageLoader.getInstance();

imageLoader.init(configuration);

btnProc = (Button) findViewById(R.id.btn_gray_process);

//4定义imageview

imageView = (ImageView) findViewById(R.id.image_view);

//-5图片路径 加载大图

 String imageUri = "assets://face.jpg";   

imageLoader.displayImage(imageUri, imageView, options);

加载大图OOM问题解决方法,缩小bitmap:

 BitmapFactory.Options options11 = new BitmapFactory.Options();

 options11.inSampleSize = 2;//图片宽高都为原来的二分之一,即图片为原来的四分之一

 bmp =BitmapFactory.decodeResource(getResources(), R.drawable.face,options11);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: