So I've been struggling with this for a better part of a day. Suppose
I have a custom ImageView that I want to overlay over a background
View (both within a RelativeLayout), which when touched, it erases
portions of the View's source bitmap like the erase tool in MS Paint,
exposing the View below it. I've checked pretty much all of the
threads (like this one:
http://groups.google.com/group/android-developers/browse_thread/thread/5b0a498664b17aa0/de4aab6fb7e97e38?lnk=gst&q=erase+transparent#
) and they suggest to use PorterDuff SRC Mode in the Paint object as
well as creating a Canvas out out the ARGB_8888 shadow copy of the
source bitmap to apply the masking.
Also, I can't set the source of the overlay ahead of time since I have
to download it over the network so that the ImageView's scale type
takes care of the scaling for me.
Every time I override onDraw, when I apply the erase on the IV's
Bitmap, it unveils a black background instead of the view below it,
even though I set the background to transparent. So I'm at my last
rope as to what to do in order to unveil the background view.
Here's what I have so far:
view constructor:
paint.setXfermode(new
PorterDuffXfermode(PorterDuff.Mode.CLEAR));
paint.setColor(Color.TRANSPARENT);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(STROKE_WIDTH);
paint.setAntiAlias(true);
overrode setImageBitmap to set my canvas from my re-configed source
bitmap:
public void setImageBitmap(Bitmap bitmap){
super.setImageBitmap(bitmap);
Drawable bd = getDrawable();
if(bd == null){
return;
}
Bitmap fullSizeBitmap = ((BitmapDrawable) bd).getBitmap();
overlay = fullSizeBitmap.copy(Config.ARGB_8888, true);
c2 = new Canvas(overlay);
}
onDraw method:
protected void onDraw(Canvas canvas) {
/*
* Override paint call by re-drawing the view's Bitmap first,
then
overlaying our path on top of it
*/
Drawable bd = getDrawable();
if(bd == null){
return;
}
Bitmap fullSizeBitmap = ((BitmapDrawable) bd).getBitmap();
if(fullSizeBitmap != null && c2 != null){
canvas.drawColor(Color.TRANSPARENT);
c2.drawBitmap(fullSizeBitmap, 0, 0, null);
c2.drawPath(path, paint);
canvas.drawBitmap(overlay, 0, 0, null);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en