-3

enter image description here

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.

Pritesh
  • 139
  • 2
  • 12

2 Answers2

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:

enter image description here

Then I inverted the custom image to :

enter image description here

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:

enter image description here

If you use the same custom image without inverting it, you will get this:

enter image description here

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