BitmapFactory.decodeResource(Resources res, int id)
因为我要对drawable目录下图片进行缩放,BitmapFactory.decodeFile的其他重载及BitmapFactory.decodeResource(Resources res, int id)都用不上,唯独要用BitmapFactory.decodeFile(filepaths, options)。
BitmapFactory.decodeResource(Resources res, int id, BitmapFactory.Options opts)
Bitmap.createBitmap(Bitmap source, int x, int y,int width, int height, Matrix m, boolean filter)方法可以通过对源图像进行缩放操作得到一个新的被缩放后的图像。具体缩放的信息有Matrix指定的。 如: Bitmap sourceBitmap = aBitmap; Matrix m = new Matrix(); m.postScale(0.5f,0.5f);//缩小为原来的一半大小 Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap,0,0,sourceBitmap.getWidth(),sourceBitmap.getHeight(),m,true); 这样就可以生成newBitmap了。
Bitmap.createBitmap(Bitmap source, int x, int y,int width, int height, Matrix m, boolean filter)方法可以通过对源图像进行缩放操作得到一个新的被缩放后的图像。具体缩放的信息有Matrix指定的。
如:
Bitmap sourceBitmap = aBitmap;
Matrix m = new Matrix();
m.postScale(0.5f,0.5f);//缩小为原来的一半大小
Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap,0,0,sourceBitmap.getWidth(),sourceBitmap.getHeight(),m,true);
这样就可以生成newBitmap了。