【问题标题】:Android ImageView get bitmap after zoom using setImageMatrixAndroid ImageView 使用 setImageMatrix 缩放后获取位图
【发布时间】:2018-07-29 13:33:18
【问题描述】:

在 Android 中,我有一个 ImageView,用户可以在 UI 中操纵位置和缩放级别。

是否可以从 ImageView 中获取缩放后的图像(更改后的图像)而不是原始图像。

这是我试过但没用的方法。

imageView.buildDrawingCache(true);
Bitmap bmp = imageView.getDrawingCache(true);

我可以得到矩阵,但不知道如何使用它。

Matrix m =  imageView.getImageMatrix();

【问题讨论】:

    标签: android bitmap imageview pinchzoom


    【解决方案1】:

    缩放效果应用于画布级别。因此,您可以做的是获取当前的 Canvas 增强功能,然后将您的位图绘制成带有更改的新位图。

    Matrix transformMatrix =  imageView.getImageMatrix()
    
    Bitmap original = bmp;
    
    Bitmap adjusted = Bitmap.createBitmap(original.getWidth(),
     original.getHeight(),
     original.getConfig());
    Canvas canvas = new Canvas(adjusted);
    canvas.setMatrix(transformMatrix);
    canvas.drawBitmap(original, 0, 0, null);
    
    //at this point adjusted bitmap contains the zoomed image
    

    【讨论】:

      【解决方案2】:

      当您从 ImageView 获取 Matrix 时,对 t 进行更改,然后使用 imageView.setImageMatrix(m) 将更改应用回 ImageView。您需要考虑使用postScale() 矩阵方法之一来更改渲染图像的大小。

      【讨论】:

        猜你喜欢
        • 2014-07-02
        • 2011-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多