Reputation: 15078
I want to re size bitmap image... so for that I am using below code
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);
but my problem is that i am getting image from drawable folder like this
Bitmap icon = BitmapFactory.decodeResource(getResources(),
Const.template[arg2]);
so how can i convert this things into file path so i can set in the following line
Bitmap bitmap = BitmapFactory.decodeFile(path, bmOptions);
and can get resizable image
Upvotes: 0
Views: 153
Reputation: 15078
The answer is become like below
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;
}
});
Upvotes: 0