Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ColorMatrix错误,显示句柄0x4422f8仍处于锁定状态_Android_Matrix - Fatal编程技术网

Android ColorMatrix错误,显示句柄0x4422f8仍处于锁定状态

Android ColorMatrix错误,显示句柄0x4422f8仍处于锁定状态,android,matrix,Android,Matrix,我想测试ColorMatrix,我的代码是: public class testColorMatrix extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); s

我想测试ColorMatrix,我的代码是:

    public class testColorMatrix extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new SampleView(this));
    }

    private static class SampleView extends View{

        BitmapFactory.Options options;
        Bitmap grayscale;
        Bitmap alpha;
        Paint grayToAlpha;
        Canvas alphaCanvas;
        float[] matrix;
        public SampleView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            // TODO Auto-generated constructor stub
            init();
        }

        public SampleView(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO Auto-generated constructor stub
            init();
        }

        public SampleView(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
            init();
        }
        public void init(){
             options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            options.inScaled = false;

            // Load source grayscale bitmap
             grayscale = BitmapFactory.decodeResource(getResources(), R.drawable.a2, options);
            // Place for  alpha mask. It's specifically ARGB_8888 not ALPHA_8, 
            // ALPHA_8 for some reason didn't work out for me. 
             alpha = Bitmap.createBitmap(grayscale.getWidth(), grayscale.getHeight(),
                    Bitmap.Config.ARGB_8888);
             matrix = new float[] {
                    5, 0, 0, 0, 10,
                    0, 5, 0, 0, 10,
                    0, 0, 5, 0, 0,
                    0, 0, 0, 1, 0};
             grayToAlpha = new Paint();

        }

        @Override
        protected void onDraw(Canvas canvas) {

            grayToAlpha.setColorFilter(null);
            canvas.drawBitmap(grayscale, 0, 0, grayToAlpha); 
            grayToAlpha.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(matrix)));
        //    alphaCanvas = new Canvas(alpha);
            // TODO Auto-generated method stub
            //super.onDraw(canvas);
        // Make sure nothing gets scaled during drawing
         alphaCanvas.setDensity(Bitmap.DENSITY_NONE);
         // Draw grayscale bitmap on to alpha canvas, using color filter that
         // takes alpha from red channel
         alphaCanvas.drawBitmap(grayscale, 0, 0, grayToAlpha);
         // Bitmap alpha now has usable alpha channel!

        }
    }
}
但它不能运行,它给了我:

05-26 02:46:18.582: ERROR/AndroidRuntime(924): ERROR: thread attach failed

05-26 02:46:29.121: ERROR/gralloc(52): [unregister] handle 0x4422f8 still locked (state=40000001)

你能给我一些建议来找出错误吗。

我也解决了我的问题:修改如下

@Override
    protected void onDraw(Canvas canvas) {

        grayToAlpha.setColorFilter(null);
        canvas.drawBitmap(grayscale, 0, 0, grayToAlpha); 
        canvas.setColorFilter(new ColorMatrixColorFilter(new ColorMatrix(matrix)));
    //    alphaCanvas = new Canvas(alpha);
        // TODO Auto-generated method stub
        //super.onDraw(canvas);
    // Make sure nothing gets scaled during drawing
     canvas.setDensity(Bitmap.DENSITY_NONE);
     // Draw grayscale bitmap on to alpha canvas, using color filter that
     // takes alpha from red channel
     canvas.drawBitmap(grayscale, 0, 0, grayToAlpha);
     // Bitmap alpha now has usable alpha channel!

    }