我想分别在图像视图的边距(10,50,10,50),(左,上,右,下)中裁剪图像。这是我的代码
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);
即,如果我的图像视图的尺寸为 200X300。那么我只想在指定区域中获取位图图像。当我尝试这样做时它显示错误
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)
我该如何解决这个问题?
谢谢