---
title: "android 图片浏览 处理"
author: "superhanliu"
date: "2009-12-31T09:22:03Z"
tags: ["Android"]
categories: ["移动开发"]
slug: "android"
draft: false
lastmod: "2009-12-31T09:22:03Z"
id: 560213
url: "https://superhanliu.iteye.com/blog/560213"
---

1 图片太大，内存不足heap space 之类的问题：

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

   options.inSampleSize = 2;//数字越大读出的图片占用的heap越小

   BitmapFactory.decodeFile(pathName,options); 

 

2 图片放大缩小的方法：

   Bitmap.createBitmap(bitMap,....);用这个方法能放大和缩小图片到想要的size

   其中Matrix类提供了更好的机制：

 

```
     //获得原始图片的size
     int bmpWidth=bmp.getWidth();
     int bmpHeight=bmp.getHeight();

     //设置缩放比例 或者根据新的size来计算出缩放比例
     double scale=1.25;

     //计算出这次要缩小的比例
     float scaleWidth=(float)(scaleWidth*scale);
     float scaleHeight=(float)(scaleHeight*scale);

     //产生resize后的Bitmap对象
     Matrix matrix=new Matrix();
     matrix.postScale(scaleWidth, scaleHeight);
     matrix.postRotate(45);//方向变换
     //得到新的bitmap
     Bitmap resizeBmp=Bitmap.createBitmap(bmp, 0, 0, bmpWidth,    bmpHeight, matrix, true);
    
```