Android 如何在画布上完全显示大型图像?

Android 如何在画布上完全显示大型图像?,android,image-resizing,Android,Image Resizing,我想以位图的形式从库中加载图像,并在自定义视图(不是imageview)上显示它。以下是加载位图的代码 private Bitmap loadBitmap(String filePath, int orientation, int width, int height) { Bitmap bitmap = null; try { BitmapFactory.Options options = new BitmapFactory.Options

我想以位图的形式从库中加载图像,并在自定义视图(不是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;
    }
私有位图加载位图(字符串文件路径、int方向、int宽度、int高度){
位图=空;
试一试{
BitmapFactory.Options=new-BitmapFactory.Options();
options.inJustDecodeBounds=true;
解码文件(文件路径,选项);
int标度=1;
如果((options.outWidth>width)| |(options.outHeight>height)){
if(options.outWidth0){
//将图像w.r.旋转到方向
矩阵=新矩阵();
矩阵。旋转后(定向);
位图=位图。创建位图(位图,0,0,宽度,高度,矩阵,真);
}
}捕获(例外e){
位图=空;
}
返回位图;
}
现在我的问题是画布不能完全显示位图。只能显示位图的一部分。我如何根据屏幕大小调整图像(不丢失清晰度,不拉伸)


提前感谢

可能您可以尝试ScaleType选项并使用最适合您的选项。有关详细信息,请访问以下链接:


但是ScaleType与imageview一起使用。我已经指定这是一个customview扩展视图。您可以使视图的高度和宽度与父视图匹配。这是否有助于适应屏幕?然后获取屏幕高度和宽度,并将画布大小设置为该值。现在,您的画布大于屏幕大小。您将视图的高度和宽度设置为与父视图匹配。这是否有助于安装屏幕?