Я хочу проверить 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)
Можете ли вы дать совет, чтобы найти ошибку.