How to perfectly merge two images and keep only the masked part

I have 2 images, image 1 contains a person and a background, image 2 contains a white silhouette of a person on a black background. I need to merge image 1 and image 2, keep only the person and save it as a PNG file without any jagged edges. How can I do this in android?Thanks
image1:
image2:
I want the result is:
I need to ensure that the output image has smooth edges and is free of jagged edges.
For feedback or comments, reach us on hello@newswire.ae