Perhaps you want to "sacle" the image to fit the button, something
like:
The image is in Bitmap bm
int width = bm.getWidth();
int height = bm.getHeight();
int newWidth = 32;
int newHeight = 32;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0,
width, height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
((ImageButton)this.findViewById(R.id.Yourbutton)).setImageDrawable(bmd);
I hope this helps you, this code works great for me to do the task of
scale an image to a size (in the sample 32x32 as you request)
Best regards.
Gabi.
On 12 nov, 01:26, Bret Foreman <[email protected]> wrote:
> I'm using the following code, which I expect would scale the
> associated image to fit within the given dimensions of the button:
>
> ImageButton.setMaxHeight(32);
> ImageButton.setMaxWidth(32);
>
> ImageButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
>
> editButton.setImageResource(R.drawable.ic_menu_edit);
>
> The image is 64X64 and I was expecting to see 32X32 on the screen.
> However, the button draws with the original 64X64 size. I can re-
> sample the image down and create a new file but I'm curious why this
> approach didn't work.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en