Aashutosh
Aashutosh

Reputation: 37

How to scale images in android?

I have 5 images in my activity.
I want to scale each big image and re-scale it to small size one by one in a thread.
I am newbie in android so please give me some sort of example which can help me better understad.

Thanks

Upvotes: 1

Views: 130

Answers (1)

Jagu
Jagu

Reputation: 762

Example:

public static Bitmap getResizedBitmap(Bitmap srcBitmap, int newWidth,
        int newHeight) {
    try {
        return Bitmap.createScaledBitmap(srcBitmap, newWidth, newHeight,
                true);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}

In Activity:

ImageView image= (ImageView) findViewById(R.id.image);
image.setImageBitmap(getResizedBitmap(bitmapImage, 120, 120));

Upvotes: 1

Related Questions