灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3256回复:0

android三种载入图片方式

楼主#
更多 发布于:2012-09-06 14:06


[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.atcpu.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

喜欢0 评分0
游客

返回顶部