android三种加载图片方式
Posted ljbguanli
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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三种加载图片方式的主要内容,如果未能解决你的问题,请参考以下文章