I have an image of height 200 and 400 pixels. The way I want to display all these images is in height of 200 pixels. I mean to say whatever the size of an image, while displaying that image I want to display image up to a height of 200 pixels. The rest portion of the image is hidden. So how that can be done? I have used one code for decoding but here it stretches the bigger size image and then displays it. In my case, I don't want the image to stretch but only display images up to height 200 pixels.
Code I used:
private Bitmap decodeFile(File f)
{
try
{
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
// Find the correct scale value.
final int REQUIRED_SIZE = 200;
int height_tmp = o.outHeight;
while(true)
{
if(height_tmp/2 < REQUIRED_SIZE)
break;
height_tmp/=2;
}
o.inSampleSize = height_tmp;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o);
}
catch (FileNotFoundException e)
{}
return null;
}