【问题标题】:android - Bitmap.createScaledBitmap results in a Bitmap sized -1android - Bitmap.createScaledBitmap 导致位图大小为 -1
【发布时间】:2011-07-05 03:41:27
【问题描述】:

我尝试使用该方法创建一个缩放位图,但是一旦我访问该位图,我的应用程序就会崩溃并显示以下消息:

"java.lang.IllegalArgumentException: y + height must be <= bitmap.height()"

当我调试它时,我可以看到在调用“createScaledBitmap”之后立即生成的位图的大小为-1,-1。如果我改用“createBitmap”,生成的位图会显示原始位图的大小。

这里应该没有人知道这是什么原因...是否有一种解决方法可以以不同的方式调整位图的大小?我在位图类中找不到任何东西,但也许这里有人知道另一种方式?

【问题讨论】:

  • 调用 createScaledBitmap 时的 dstWidth 和 dstHeight 是什么?

标签: android graphics bitmap scaling


【解决方案1】:

首先,我想澄清一下,您从 Bitmap.createBitmap 方法而不是从 Bitmap.createScaledBitmap 收到错误。 createBitmap 的语法如下所示,

Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)

    Parameters
    source: The bitmap we are subsetting
    x: The x coordinate of the first pixel in source
    y: The y coordinate of the first pixel in source
    width: The number of pixels in each row
    height: The number of rows
    m: Optional matrix to be applied to the pixels
    filter: true if the source should be filtered. Only applies if the matrix contains more than just translation.

发生错误是因为,

x、y、宽度、高度值超出源位图的尺寸。

【讨论】:

    猜你喜欢
    • 2018-06-07
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多