圖片文件轉為Bitmap對象
String filePath="c:/01.jpg";
Bitmap bitmap=BitmapFactory.decodeFile(filePath);
如果圖片過大,可能導致Bitmap對象裝不下圖片
解決辦法:
String filePath="c:/01.jpg";
Bitmap bitmap=BitmapFactory.decodeFile(filePath,getBitmapOption(2)); //將圖片的長和寬縮小味原來的1/2
private Options getBitmapOption(int inSampleSize){
System.gc();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
options.inSampleSize = inSampleSize;
return options;
}