码迷,mamicode.com
首页 > 移动开发 > 详细

android三种加载图片方式

时间:2017-06-22 09:56:48      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:class   rgb   content   imp   graph   nbsp   public   alt   指定   

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; 
    } 

android三种加载图片方式

标签:class   rgb   content   imp   graph   nbsp   public   alt   指定   

原文地址:http://www.cnblogs.com/ljbguanli/p/7063008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!