android三种载入图片方式

时间:2014-09-18 16:33:54   收藏:0   阅读:275
package smalt.music.utils; 
 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.graphics.BitmapFactory.Options; 
 
//加载图片的方法:3种 
public class BitmapUntil { 
    // 直接载入图片 
    public static Bitmap getBitmap(String path) { 
        Bitmap bt = BitmapFactory.decodeFile(path); 
        return bt; 
    } 
 
    // 指定大小载入图片
    public static Bitmap getBitmap(String path, int size) { 
        Options op = new Options(); 
        op.inSampleSize = size; 
        Bitmap bt = BitmapFactory.decodeFile(path, op); 
        return bt;  www.2cto.com
    } 
 
    // 按宽高压缩载入图片
    public static Bitmap getBitmap(String path, int width, int heigh) { 
        Options op = new Options(); 
        op.inJustDecodeBounds = true; 
        Bitmap bt = BitmapFactory.decodeFile(path, op); 
        int xScale = op.outWidth / width; 
        int yScale = op.outHeight / heigh; 
        op.inSampleSize = xScale > yScale ? xScale : yScale; 
        op.inJustDecodeBounds = false; 
        bt = BitmapFactory.decodeFile(path, op); 
        return bt; 
    } 

原文:http://blog.csdn.net/tw19811220/article/details/39373321

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!