znl_12 2013-04-17 03:43 采纳率: 0%
浏览 4790
已采纳

使用 setPixels 的错误

我想编辑 images,但是使用 setPixels 时获得错误

 picw = pic.getWidth();
        pich = pic.getHeight();
        picsize = picw*pich;        
        int[] pix = new int [picsize];
        pic.getPixels(pix, 0, picw, 0, 0, picw, pich);  
        pic.setPixels(pix,0,pic.getWidth(),0,0,pic.getWidth(),pic.getHeight());

使用 setPixels 获得非法状态异常

由于: java.lang.IllegalStateException
   android.graphics.Bitmap.setPixels(Bitmap.java:878)
   com.sandyapps.testapp.testapp.onCreate(testapp.java:66)
  • 写回答

2条回答

  • 搬不搬砖 2013-04-17 09:31
    关注

    根据文档中的说明

    public void setPixel (int x, int y, int color)
    
    Since: API Level 1
    Write the specified Color into the bitmap (assuming it is mutable) at the x,y coordinate.
    Parameters
    
    x   The x coordinate of the pixel to replace (0...width-1)
    y   The y coordinate of the pixel to replace (0...height-1)
    color   The Color to write into the bitmap
    Throws
    
    IllegalStateException   if the bitmap is not mutable
    IllegalArgumentException    if x, y are outside of the bitmap's bounds.
    

    IllegalStateException表示这个位图是不可变的,要修改就自己建一个副本吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥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发现不可读取的内容