,你可以用它來獲取當前運行的屏幕:
@Override
public void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
screenW = w;
screenH = h;
}
然後用這個,所以你被加載到內存合理地加載位圖:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;
if(imageWidth > imageHeight){
options.inSampleSize = calculateInSampleSize(options,screenH,screenW);
}else{
options.inSampleSize = calculateInSampleSize(options,screenW,screenH);
}
options.inJustDecodeBounds = false;
photo = BitmapFactory.decodeFile(selectedImagePath,options);
方法:
public int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and width
final int heightRatio = Math.round((float) height/(float) reqHeight);
final int widthRatio = Math.round((float) width/(float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
如果我需要比原圖大小大PIC .. – supermantoby 2013-04-10 02:28:14
你想要做什麼只記得,我認爲每個應用程序的堆內存16MB它,說一個普通camerashot是一個很大的內存作爲一個完整的位圖,說該設備是480X320加載,而不是完整的水庫,太多youll超載 – JRowan 2013-04-10 02:34:17
inSampleSize不能拉伸位圖..否則我將能夠使用它... – supermantoby 2013-04-10 02:42:25