1

I'm trying to apply a gradient mask to a blur layer in Android. Something like this:

enter image description here

I'm trying using this code:

Bitmap mutable = Bitmap.createBitmap(lebg.getWidth(), lebg.getHeight(), Bitmap.Config.ARGB_8888);  
Canvas canvas = new Canvas(mutable);  
Paint paint = new Paint();  
paint.setFilterBitmap(false);   
canvas.drawBitmap(lebg, 0, 0, paint);  
canvas.drawBitmap(leblur, 0, 0, paint);  
paint.setXfermode(new PorterDuffXfermode(Mode.DST_OUT));  
canvas.drawBitmap(mask, 0, 0, paint);

Any idea?

Thanks!

The first image is the blur layer. The second image is the original layer. The third image is the mask layer. The last image is the result image.

Petros Koutsolampros
  • 2,790
  • 1
  • 14
  • 20
noahrod
  • 43
  • 1
  • 7
  • http://stackoverflow.com/a/10028267/538169 – pawelzieba Jun 15 '12 at 19:10
  • @pawelzieba Actually I'm using that blur function to get the first image, I already have the first 3 images i just want to get the last one. – noahrod Jun 15 '12 at 20:40
  • @MichałK Yes, i was trying to use this code: http://stackoverflow.com/questions/4159959/android-circular-gradient-alpha-mask but the transparent pixels turns into black pixels. and i'm sure I´m setting a bitmap with alpha. (I've tried ALPHA_8 and ARGB 8888) – noahrod Jun 15 '12 at 20:43
  • Add your code please, it's hard to suggest anything without actually seeing your code. +1 for the pics, though;) – Michał Klimczak Jun 15 '12 at 21:14
  • @MichałK Done, sorry about that, I'm just new here, thanks for your advice :) – noahrod Jun 15 '12 at 21:57
  • I'm not really well versed in android code, but it looks to me like right now you are first drawing the background onto your canvas, then you draw the blurred foreground over it (which means the background will be entirely covered and lost) and then you apply the gradient to the canvas' alpha channel meaning you end up with a transparent hole in the middle. I think you have to use a second temporary Paint onto which you draw the blurred layer and to which you apply the gradient mask. Then you draw this temporary layer (with the hole) over the original image. – Quasimondo Jun 21 '12 at 19:51

0 Answers0