2011-05-26 4 views
0

je veux tester ColorMatrix, mon code est:ColorMatrix erreur et apparaissent poignée 0x4422f8 toujours verrouillé

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! 

     } 
    } 
} 

mais il ne peut pas courir, DDMs il me donne:

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) 

peut vous donner quelques conseils pour trouver l'erreur.

Répondre

1

je résous aussi ma question: Modifier comme suit

@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! 

    } 
Questions connexes