Bitmap.createBitmap参数异常之java.lang.IllegalArgumentException: width and height must be > 0
来源:互联网 发布:gzip压缩算法比较 编辑:程序博客网 时间:2024/05/14 18:55
代码:
public static Bitmap readBitmapInSize(Context paramContext, int paramInt,
int width, int height) {
Matrix matrix = new Matrix();
Bitmap bitmap = readBitmap(paramContext, paramInt);
matrix.setScale( width / bitmap.getWidth(), height
/ bitmap.getHeight());
Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), matrix, true);
return resizeBmp;
}
报错信息:
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): FATAL EXCEPTION: main
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): java.lang.IllegalArgumentException: width and height must be > 0
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.graphics.Bitmap.createBitmap(Bitmap.java:603)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at com.zoipuus.mypet.util.BitmapOperation.readBitmapInSize(BitmapOperation.java:31)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at com.zoipuus.mypet.util.CreateViewUtil.createIconView(CreateViewUtil.java:45)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at com.zoipuus.mypet.service.MyWindowService.createIconView(MyWindowService.java:91)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at com.zoipuus.mypet.view.MoveImageView.onTouchEvent(MoveImageView.java:155)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.view.View.dispatchTouchEvent(View.java:5541)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.view.View.dispatchPointerEvent(View.java:5721)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.os.Looper.loop(Looper.java:137)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at android.app.ActivityThread.main(ActivityThread.java:4424)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at java.lang.reflect.Method.invoke(Method.java:511)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-04 13:25:36.422: ERROR/AndroidRuntime(2009): at dalvik.system.NativeStart.main(Native Method)
打了断点看了一下数值都是大于0的,一开始以为bitmap的获取方法不对,换了也一样出错。功夫不负有心人,最后找到解决办法的灵感来自这个网站4楼的回答http://bbs.csdn.net/topics/370255160。自己的猜测:Bitmap的getWidth和getHeight方法返回的是int类型,而Matrix的setScale方法需要的是float类型,所以如果分子小于分母就会得到0,就会报错。检验猜测:把int类型转换为float类型,matrix.setScale(1.0f * width / bitmap.getWidth(), 1.0f * height/ bitmap.getHeight());问题终于解决了。如果有错恳请大神指导。
0 0
- Bitmap.createBitmap参数异常之java.lang.IllegalArgumentException: width and height must be > 0
- Bitmap.createBitmap java.lang.IllegalArgumentException: width and height must be > 0 问题解决
- Bitmap.createBitmap java.lang.IllegalArgumentException: width and height must be > 0 问题解决
- bitmap 缩放 java.lang.IllegalArgumentException: width and height must be > 0
- java.lang.IllegalArgumentException: width and height must be > 0
- createBitmap — java.lang.IllegalArgumentException: x must be < bitmap.width()错误的解决
- Fragment中测量宽度、高度, Caused by: java.lang.IllegalArgumentException: width and height must be > 0
- Android 使用createBitmap时出现异常 width and height must be > 0
- java.lang.IllegalArgumentException: Width (0) and height (560) cannot be <= 0
- java.lang.IllegalArgumentException: x + width must be <= bitmap.width()问题
- IllegalArgumentException : y + height must be <= bitmap.height()
- java.lang.IllegalArgumentException: Service Intent must be explicit异常说明
- java.lang.IllegalArgumentException: Service Intent must be explicit 异常说明
- java.lang.IllegalArgumentException: Service Intent must be explicit 异常解决
- Bitmap android.graphics.Bitmap.createBitmap(int width, int height, Config config) Config参数的说明
- Bitmap android.graphics.Bitmap.createBitmap(int width, int height, Config config) Config参数的说明
- Bitmap android.graphics.Bitmap.createBitmap(int width, int height, Config config)张第三个参数的含义
- [异常整理]java.lang.IllegalArgumentException: Attribute value must not be null
- 全新android Tab控件PagerSlidingTabStrip最简使用方法
- 开始写博客
- 运算符重载
- 对比传统关系型数据库,NoSQL有着非常显著的性能和扩展性优势,然而这些优点却建立在一些关键功能的丢失之上,比如事务、join等。那么在数据体积激增的当下,究竟哪个数据库才会适合你的场景
- 101到200间的素数及其个数
- Bitmap.createBitmap参数异常之java.lang.IllegalArgumentException: width and height must be > 0
- 多重继承
- Boost库问题:无法识别的外部符号……
- Intent知识小学习
- HDU 1272 小希的迷宫
- VS关闭CodeLens 功能
- 第32题
- M文件实现GUI菜单结构----UImenu、UIcontextmenu、UIcontrol
- 书单列举及进展