当前位置:操作系统 > 安卓/Android >>

android三种载入图片方式

[java] 
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.zzzyk.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; 
    } 

作者:yhm2046
补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,