【问题标题】:Android - Save ImageView to file with full resolution imageAndroid - 将 ImageView 保存到具有全分辨率图像的文件
【发布时间】:2011-12-27 10:44:38
【问题描述】:

我将图像放在 ImageView 中,并实现了多点触控来调整图像大小和在 ImageView 中移动图像。现在我需要将调整大小的图像保存到图像文件中。我已经尝试过 .getDrawingCache() 但该图像具有 ImageView 的大小。我希望图像显示 ImageView 显示的内容,但具有全分辨率(大于 ImageView)。

有什么想法吗?

【问题讨论】:

    标签: android save imageview


    【解决方案1】:

    您可以在后台保存一个位图对象,您可以使用以下代码调整其大小:

    Matrix matrix = new Matrix();
    matrix.postScale(scaledWidth, scaledHeight);
    
    Bitmap resizedBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
        originalBitmap.width(), originalBitmap.height(), matrix, true); 
    

    稍后使用此代码保存:

    OutputStream fOut = null;
    File file = new File(strDirectoy,imgname);
    fOut = new FileOutputStream(file);
    
    resizedBitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut);
    fOut.flush();
    fOut.close();
    

    【讨论】:

      【解决方案2】:

      我的解决方案是使用我用于 ImageView 的矩阵来获取翻译,并且我还拥有该图像的比例。使用这两个我裁剪了原始图像。

      Bitmap resizedBitmap = Bitmap.createBitmap(
                              BitmapFrontCover, (int) UpperLeftCornerX,
                              (int) UpperLeftCornerY, (int) CropWidth,
                              (int) CropHeight);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-19
        • 2013-06-26
        • 1970-01-01
        • 1970-01-01
        • 2018-07-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多