[英]How to show a large image completely on a canvas?
I want to load an image from gallery as a bitmap an show it on a custom view(not an imageview).Here is the code for loading bitmap. 我想从图库中加载图像作为位图,然后在自定义视图(不是imageview)上显示。这是加载位图的代码。
private Bitmap loadBitmap(String filePath, int orientation, int width, int height) {
Bitmap bitmap = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
int scale = 1;
if ((options.outWidth > width) || (options.outHeight > height)) {
if (options.outWidth < options.outHeight) {
scale = Math.round((float) options.outWidth / width);
} else {
scale = Math.round((float) options.outHeight/ height);
}
}
options.inSampleSize = scale;
options.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(filePath, options);
if (orientation > 0) {
// rotate the image w.r.to orientation
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
bitmap = Bitmap.createBitmap(bitmap, 0, 0,width,height, matrix, true);
}
} catch (Exception e) {
bitmap = null;
}
return bitmap;
}
Now my problem is that the canvas does not show the bitmap completely.Only a part o it.How can i adjust the image (without losing its clarity,not stretching) with screen size? 现在我的问题是,画布无法完全显示位图。它只有一部分。如何调整屏幕尺寸的图像(不失去清晰度,不会拉伸)?
Thanks in Advance 提前致谢
May be you can try the ScaleType options and use the one whihc suits you the best. 也许您可以尝试ScaleType选项,并使用最适合您的一种。 Follow the link below for details:
请点击以下链接了解详细信息:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.