我正在尝试编写一个简单的幻灯片放映程序。我希望它显示不同尺寸的图片,然后缩放,这样宽度就会填满屏幕。我可以更改图像视图的大小,并在调试器中将其设置为新宽度,但它不会缩放位图,这是一种方法吗??????
代码:
ImageView picImage = (ImageView) findViewById(0);// R.id.viewpic);
try {
String FileName = "canon20.png";
AssetManager assetManager = getAssets();
InputStream inputStream;
inputStream = assetManager.open(FileName);
Bitmap icon = BitmapFactory.decodeStream(inputStream);
int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
int bw = icon.getWidth();
float t = (float) screenWidth / (float) bw;
picImage.setImageBitmap(icon);
picImage.getLayoutParams().width = screenWidth;
picImage.getLayoutParams().height = (int) (icon.getHeight() * t);
} catch (IOException e) {
}