android - Bitmap.createScaledBitmap 导致位图大小为 -1
我尝试使用该方法创建缩放位图,但一旦访问该位图,我的应用程序就会崩溃并显示以下消息:
“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我想澄清一下,您从 Bitmap.createBitmap 方法中收到错误,而不是从 Bitmap.createScaledBitmap 中收到错误。 createBitmap的语法如下所示,
发生错误,因为
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,
An error is occured because,
x, y, width, height values are outside of the dimensions of the source bitmap.