android三種加載圖片方式
阿新 • • 發佈:2017-06-22
factor trac turn post static col ati 三種 sam
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 ?
bt = BitmapFactory.decodeFile(path, op);
return bt;
}
}
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三種加載圖片方式