抛出:IllegalArgumentException:X +宽度必须< = bitmap.width()在android系统 [英] IllegalArgumentException: x + width must be <= bitmap.width() in android

查看:553
本文介绍了抛出:IllegalArgumentException:X +宽度必须< = bitmap.width()在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用保证金(10,50,10,50)分别裁剪图像(左,上,右,下)的ImageView的的。这里是我的code

I want to crop an image with in a margin (10,50,10,50),(left,top,right,bottom) respectively of an imageview. Here is my code

Bitmap bitmap = Bitmap.createBitmap(imgView.getWidth(),imgView.getHeight(), Bitmap.Config.ARGB_8888);

Bitmap result = Bitmap.createBitmap(bitmap, (imgView.getLeft() + 10),
                imgView.getTop() + 50,imgView.getRight() - 10,imgView.getBottom() - 50);
bitmap.recycle();
Canvas canvas = new Canvas(result);
imgView.draw(canvas);

也就是说,如果我的ImageView的是维200X300.then我想在指定区域中唯一的。当我试图做到这一点用得到位图图像它显示误差

ie, if my imageview is of dimension 200X300.then i want to get the bitmap image with in the specified area only .When I am trying to do this It shows error

 FATAL EXCEPTION: main
 java.lang.IllegalArgumentException: x + width must be <= bitmap.width()
    at android.graphics.Bitmap.createBitmap(Bitmap.java:410)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:383)
    at android.view.View.performClick(View.java:2485)
    at android.view.View$PerformClick.run(View.java:9080)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3687)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    at dalvik.system.NativeStart.main(Native Method)

我怎样才能解决呢?

How can i solve this?

感谢

推荐答案

尝试这一点,看看它是否工作:

try this and see if it works:

// using this method createBitmap(source, x, y, width, height)
Bitmap result = Bitmap.createBitmap(bitmap, 10,
            50, imgView.getWidth() - 20, imgView.getHeight() - 100);

getLeft 和其他用于获取在其父视图的位置。位图的不是尺寸。

getLeft and others is used to get the position of the view in its parent. Not the dimension of the bitmap.

这篇关于抛出:IllegalArgumentException:X +宽度必须&LT; = bitmap.width()在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆