我想重新调整位图图像...所以我正在使用下面的代码
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
int scaleFactor = Math.min(photoW / 100, photoH / 100);
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(path, bmOptions);
但我的问题是我从像这样的可绘制文件夹中获取图像
Bitmap icon = BitmapFactory.decodeResource(getResources(),
Const.template[arg2]);
所以如何将这些内容转换为文件路径,以便我可以在以下行中进行设置
Bitmap bitmap = BitmapFactory.decodeFile(path, bmOptions);
并且可以获得可调整大小的图像
答案 0 :(得分:1)
我不明白,为什么要使用decodeFile()
?我很确定你可以使用
BitmapFactory.decodeResource(getResources(), Const.template[arg2]), bmOptions)
答案 1 :(得分:0)
答案如下所示
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
// If set to true, the decoder will return null (no bitmap), but
// the out... fields will still be set, allowing the caller to
// query the bitmap without having to allocate the memory for
// its pixels.
bmOptions.inJustDecodeBounds = true;
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW / 100, photoH / 100);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), Const.template[arg2],bmOptions);
Drawable draw = new BitmapDrawable(getResources(), bitmap);
/* place image to textview */
TextView txtView = (TextView) findViewById(R.id.imgChooseImage);
txtView.setCompoundDrawablesWithIntrinsicBounds(draw, null,
null, null);
position = arg2;
}
});