本文介绍了用的setPixels错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编辑图像。但我得到的错误使用的setPixels。

  picw = pic.getWidth();
        PICH = pic.getHeight();
        picsize = picw * PICH;
        INT [] PIX =新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)
 

解决方案

我觉得你的位图是不可变的(见setPixel()'s文档)。

如果是这样,创建此位图的可变副本(使用 Bitmap.copy(Bitmap.Config配置,布尔isMutable)为例)和工作在这一个。

i am trying to edit images. but i am getting errors with 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());

but i am getting illegal state exception with setPixels

Caused by: java.lang.IllegalStateException
  at android.graphics.Bitmap.setPixels(Bitmap.java:878)
  at com.sandyapps.testapp.testapp.onCreate(testapp.java:66)
解决方案

I think your Bitmap is not mutable (see setPixel()'s documentation).

If so, create a mutable copy of this Bitmap (using Bitmap.copy(Bitmap.Config config, boolean isMutable) as an example) and work on this one.

这篇关于用的setPixels错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:02