很无语的事情,昨天碰到了200x1000的位图,然后我把这个位图用public static Bitmap preScaleBitmap(Bitmap temp, float drawScale) {
float scaleWidth = DataManager.deviceWidth - 20;
// float scaleHeight=(int)((DataManager.deviceWidth-20)*drawScale);
float scale = scaleWidth / temp.getWidth();
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
// matrix.postScale(0.5f, 0.5f);
Bitmap temp2 = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(),
temp.getHeight(), matrix, true);
return temp2;
}这个函数拉到了手机屏幕的宽度-20px,长度也按这宽度增的比例进行的。 我手机用的480x800,如此的话,这个图片还是要滚3个屏幕才能看完。但是在滚动的过程中经常会出现挂掉~有没有什么好的方法处理这个图片的显示啊? 设计要求是拉到屏幕宽度,高度按宽度拉伸比例走~
float scaleWidth = DataManager.deviceWidth - 20;
// float scaleHeight=(int)((DataManager.deviceWidth-20)*drawScale);
float scale = scaleWidth / temp.getWidth();
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
// matrix.postScale(0.5f, 0.5f);
Bitmap temp2 = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(),
temp.getHeight(), matrix, true);
return temp2;
}这个函数拉到了手机屏幕的宽度-20px,长度也按这宽度增的比例进行的。 我手机用的480x800,如此的话,这个图片还是要滚3个屏幕才能看完。但是在滚动的过程中经常会出现挂掉~有没有什么好的方法处理这个图片的显示啊? 设计要求是拉到屏幕宽度,高度按宽度拉伸比例走~
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.picture, options);
int orgHeight = options.outHeight;
int orgWidth = options.outWidth;
options.inSampleSize = orgWidth/Static.screenWidth;
options.inJustDecodeBounds = false;
Static.picture = BitmapFactory.decodeResource(getResources(), R.drawable.picture, options);
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.picture, options); //这里的位图是空的,原因是options.inJustDecodeBounds为true,但是可以获得位图的长宽,所以此次内存不会溢出 int orgHeight = options.outHeight;
int orgWidth = options.outWidth;
options.inSampleSize = orgWidth/Static.screenWidth; //按照比例缩放到屏幕宽度
options.inJustDecodeBounds = false;
Static.picture = BitmapFactory.decodeResource(getResources(), R.drawable.picture, options); //绘制缩放后的位图