Peter
Peter

Reputation: 5131

Set/Scale image size in android app

So In my code i take an image file location from an array called filelocationarray. Then i use .setImageBitmap to set the ImageView to the image file. What i want to do is set the size of the ImageView as it displays on the screen. In java i used this code:

img.getScaledInstance(75, 75,java.awt.Image.SCALE_SMOOTH);

But i haven't been able to figure out a similar way in android. Bellow is my code that i use so far to display the image. Can anyone give me som ehelp?

        Bitmap bMap = BitmapFactory.decodeFile(filelocationarray.get(0));
        ImageView iv = (ImageView) findViewById(R.id.imageView1);
        iv.setImageBitmap(bMap);

EDIT:

I tried using this code but it doesn't work:

        Bitmap bMap;
        bMap.createScaledBitmap (accstringarray.get(acc1int), 75, 75, true);
        ImageView iv = (ImageView) findViewById(R.id.imageView1);
        iv.setImageBitmap(bMap);

What am i doing wrong?

Upvotes: 1

Views: 3849

Answers (1)

mgv
mgv

Reputation: 8484

Use the method #createScaledBitmap() of android.graphics.Bitmap.

Upvotes: 1

Related Questions