我有一个高度为 200 和 400 像素的图像。我想显示所有这些图像的方式是 200 像素的高度。我的意思是说无论图像的大小如何,在显示该图像时,我想将图像显示到 200 像素的高度。图像的其余部分被隐藏。那怎么做呢?我使用了一个代码进行解码,但在这里它拉伸了更大尺寸的图像,然后显示它。就我而言,我不希望图像拉伸,而只显示高度为 200 像素的图像。
我使用的代码:
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;
}