0

I'm having trouble setting an alpha value of a region path drawn on a bitmap, using SurfaceView.

I'm creating my bitmap and erase with a black color (and 255 as alpha)

bitmap = Bitmap.createBitmap(480, 724, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(0xFF000000);
Canvas canvas = new Canvas(bitmap);

Next, in my onDraw method I draw a path on the bitmap with his own alpha, white color as stroke, black as fill color and 1 as alpha value :

Paint border = new Paint();
border.setStyle(Paint.Style.STROKE);
border.setStrokeWidth(1);
border.setStrokeCap(Paint.Cap.BUTT);
border.setStrokeJoin(Paint.Join.MITER);
border.setColor(Color.WHITE);

Paint inside = new Paint();
inside.setAntiAlias(false);
inside.setStyle(Paint.Style.FILL);
int alpha = 1<<24;
inside.setColor(alpha);

canvas.drawBitmap(bitmap,0,0, null);
canvas.drawPath(path, border);
canvas.drawPath(path, inside);

Finally, in my onTouchEvent method, i'm doing this :

int index = bitmap.getPixel((int)event.getX(), (int)event.getY());
int alpha = index >>> 24;
Log.v("TAG", " Region path alpha :"+ String.valueOf(alpha));

So, when I click inside the path region, I'm expecting to have 1 (0x01) as alpha value, but instead I'm still have 255 (0xFF). What's wrong with that ? Thanks in advance.

  • This method is based on a previous answer posted by @Brian on [link](http://stackoverflow.com/questions/2597590/how-can-i-tell-if-a-closed-path-contains-a-given-point), but does not works fine for me...Hope this will help you understand my qestion. – Jean Pierre Sep 26 '11 at 08:54

1 Answers1

0

I am trying this in usual Java, and getting no errors ! probably you should try debugging the value of index. Output the value of index and check, or just try

Color.alpha(index)

http://developer.android.com/reference/android/graphics/Color.html#alpha(int)

Dhruv Baldawa
  • 158
  • 1
  • 10