I want any image to take the shape of this black part. How will I be able to do this in android? I have many other designs like this.
Asked
Active
Viewed 1,247 times
-3
-
2you can set "transparent" color to the black part and match background color to the rest of the part, then overlap this to any image. You will get your desired result. – tahsinRupam Jan 29 '17 at 07:30
-
If you are using OpenCV you can use `cv2.bitwise_and()` – Jeru Luke Jan 29 '17 at 07:59
-
Make sure that the image you are using and the custom image in question are of the same size... – Jeru Luke Jan 29 '17 at 08:12
-
use `PorterDuffXfermode` with `DST_IN` / `SRC_IN` mode – pskink Jan 29 '17 at 08:22
-
Thanks I'll check it. – Pritesh Jan 29 '17 at 08:42
2 Answers
1
You can check this one. https://github.com/mafujuls/mafs-image-shape
Integrate this lib:
dependencies {
compile 'com.mafstech.libs:mafs-image-shape:1.0.4'
}
After implementing, you just need to write a single line code with some parameter. That is:
Shaper.shape(MainActivity.this, R.drawable.your_image, R.drawable.your_shaped_image, your_image_view, height, weight);
For more detail: https://github.com/mafujuls/mafs-image-shape

Mafujul
- 1,090
- 10
- 15
0
You can work this out using OpenCV for Android.
Resize the image you want to work with to the size of the custom image. Here is mine:
Then I inverted the custom image to :
I used the function cv2.bitwise_and()
as in the following:
final = cv2.bitwise_and(resized,resized,mask = thresh)
cv2.imwrite('final.jpg',final)
and obtained this:
If you use the same custom image without inverting it, you will get this:
Hope it helps :)

Jeru Luke
- 20,118
- 13
- 80
- 87
-
Thanks but I need the background to be transparent and only the shape should be filled – Pritesh Jan 29 '17 at 08:49
-
Ok, so to do that use the image above and follow [THIS ANSWER](http://stackoverflow.com/questions/41526023/php-remove-white-background-from-the-image-and-make-it-transparent/41567320#41567320). I would have used the **GrabCut Algorithm** – Jeru Luke Jan 29 '17 at 08:55