android - Bitmap.createScaledBitmap 导致位图大小为 -1

发布于 2024-11-18 14:24:50 字数 335 浏览 4 评论 0原文

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

“java.lang.IllegalArgumentException:y + height必须是<= bitmap.height()”

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

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

i try creating a scaled bitmap using that method but once i access the bitmap, my app crashes with the following message:

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

When I debug it, I can see that immediately after calling "createScaledBitmap", the resulting bitmap has a size of -1, -1. if i use "createBitmap" instead, the resulting bitmap does show the size of the original bitmap.

Should nobody here know what the cause of this is... is there maybe a workaround to resize a bitmap differently? I couldn't find anything in the bitmap class but maybe somebody here knows another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-11-25 14:24:50

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

Bitmap.createBitmap(位图源,int x,int y,int宽度,int高度,矩阵m,布尔过滤器)

    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、宽度、高度值超出了源位图的尺寸。

First, i want to clarify that you are getting an error from Bitmap.createBitmap method, not from Bitmap.createScaledBitmap. Syntax of createBitmap is as shown below,

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.

An error is occured because,

x, y, width, height values are outside of the dimensions of the source bitmap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文