【问题标题】:Apply matrix from one bitmap to another bitmap with different dimension but with same preview result将矩阵从一个位图应用到另一个具有不同尺寸但具有相同预览结果的位图
【发布时间】:2016-08-24 05:24:07
【问题描述】:

我正在创建一个显示不同位图尺寸的简单预览应用程序。

我想复制第一个位图矩阵并将其用于具有更大尺寸的第二个位图。

我希望第二张图片的预览与第一张一样。如何将矩阵应用于第二张图像,以便在第二张分辨率更高的图像上应用时,预览与第一张图像相同。我正在用这个搜索一周,但没有找到运气,所以我把它放在这里。希望能帮到你。

【问题讨论】:

  • 你的“矩阵”是什么意思?
  • 嗨@pskink android.graphics.Matrix 先生。我在图 1 中有矩阵(旋转、缩放、移动)。
  • 所以使用postScale,你可以得到原始的Matrix,而不是Bitmap,而是来自ImageView,这表明Bitmap
  • 我找到了这个帖子stackoverflow.com/questions/18426700/…,但没有答案。
  • 你打电话给postScale了吗?

标签: android matrix matrix-multiplication


【解决方案1】:

我知道这是一个老问题,但只在谷歌搜索中找到了这个问题,所以给出了我的解决方案:

    private fun applyMatrixWithDiffSize(original: Bitmap, dst: Bitmap, matrix: Matrix): Bitmap {

    //get the ratio between the images, (assuming you are keeping the aspect ratio)
    val ratio = original.width / dst.width.toFloat()

    //add scale to a new matrix to fit all changes in the new sized bitmap
    val scaleMatrix = Matrix()
    scaleMatrix.preScale(ratio, ratio)

    //pre concat so the scale gets before the rest of the changes
    matrix.preConcat(scaleMatrix)

    //create the new bitmap
    return Bitmap.createBitmap(
        dst, 0, 0,
        dst.width, dst.height, matrix, true)
}

【讨论】:

    猜你喜欢
    • 2018-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 2023-01-26
    • 2011-08-16
    • 1970-01-01
    相关资源
    最近更新 更多