bluetooth99 2012-11-01 07:28 采纳率: 0%
浏览 11662

java.lang.IllegalArgumentException: x 一定要小于 bitmap.width()

获取屏幕截图,用裁剪图片创建位图的时候出现了错误,

先看看我的代码吧:

View v1 = mKittyBGLayer.getRootView();
    v1.setDrawingCacheEnabled(true);
    Bitmap source = v1.getDrawingCache();
    int width = source.getWidth();
    int height = source.getHeight();
    System.out.println("vListView : -"+vListView.getWidth());
    System.out.println("hListView : -"+hListView.getHeight());
    System.out.println("Width : -"+width);
    System.out.println("Height : -"+height);
    bitmap = Bitmap.createBitmap(source, vListView.getWidth(), 0, width, height - hListView.getHeight());

日志也看一下:

11-01 11:00:31.419: I/System.out(1658): vListView :- 60
        11-01 11:00:31.429: I/System.out(1658): hListView :- 60
        11-01 11:00:31.429: I/System.out(1658): Width :- 480
        11-01 11:00:31.429: I/System.out(1658): Height :- 320
        11-01 11:00:31.429: D/AndroidRuntime(1658): Shutting down VM
        11-01 11:00:31.429: W/dalvikvm(1658): threadid=1: thread exiting with uncaught exception  (group=0x40018560)
        11-01 11:00:31.429: E/AndroidRuntime(1658): FATAL EXCEPTION: main
        11-01 11:00:31.429: E/AndroidRuntime(1658): java.lang.IllegalArgumentException: x + width  must be <= bitmap.width()
        11-01 11:00:31.429: E/AndroidRuntime(1658):     at android.graphics.Bitmap.createBitmap(Bitmap.java:410)
        11-01 11:00:31.429: E/AndroidRuntime(1658):     at android.graphics.Bitmap.createBitmap(Bitmap.java:383)
        11-01 11:00:31.429: E/AndroidRuntime(1658):     at com.appsehs.android.CUTECRAZYKITTENDRESSUPGAME.PhotoSortrActivity.takeScreenShot(PhotoSortrActivity.java:247)
        11-01 11:00:31.429: E/AndroidRuntime(1658):     at com.appsehs.android.CUTECRAZYKITTENDRESSUPGAME.PhotoSortrActivity.onOptionsItemSelected(PhotoSortrActivity.java:274)
        11-01 11:00:31.429: E/AndroidRuntime(1658):     at android.app.Activity.onMenuItemSelected(Activity.java:2205)

程序里面x < bitmap.getWidth也就是60 < 480

但是报错了

  • 写回答

1条回答

  • Billy_崔海斌 2012-11-30 08:36
    关注

    Bitmap createBitmap (Bitmap source, int x, int y, int width, int height)
    x + width must equal or less than source.getWidth(), in your case, 60 + 480 > 480, so error occur.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题