首页 > 代码库 > android三种加载图片方式
android三种加载图片方式
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 ?
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三种加载图片方式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。