I just want to know is there anyway to draw a pattern over a bitmap , something like this. For example, I want to draw a pattern of this over my bitmap.
Asked
Active
Viewed 533 times
-3

Umair Mustafa
- 209
- 4
- 13
-
see `PorterDuffXfermode`, some background [here](http://ssp.impulsetrain.com/porterduff.html) – pskink Jan 31 '18 at 07:41
2 Answers
2
You can definitely set a bitmap.And creating a canvas over it.Once canvas gets created over the bitmap, you can definitely draw custom patterns over it.
You can see the complete guide how to draw text here:
https://www.skoumal.net/en/android-how-draw-text-bitmap/
Long story short:
Copy your bitmap to make it mutable and create Canvas based on it.

GAGAN BHATIA
- 591
- 5
- 17
1
Option 1: Transparent Foreground
If you follow the process described here to merge the two images, you can draw one image onto another. Simply change the opacity of the top-most image as described here. Consider the following example:
Bitmap bitmap = Bitmap.createBitmap(/* width */, /* height */, Config.ARGB_8888);
Paint alpha = new Paint();
alpha.setAlpha(/* alpha */);
Canvas canvas = new Canvas(bitmap);
Bitmap background = BitmapFactory.decodeResource(
getResources(), R.drawable.background);
Bitmap foreground = BitmapFactory.decodeResource(
getResources(), R.drawable.pattern);
canvas.drawBitmap(background, /* xPos */, /* yPos */, null);
canvas.drawBitmap(foreground, /* xPos */, /* yPos */, alpha);
Option 2: Background Masked with Foreground
Alternatively, if you are trying to mask the image, you can consider implementing the solution found here.

joshuaneigh
- 68
- 8