Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrupt pixels when combining images in iOS
    primarykey
    data
    text
    <p>I'm trying to combine two photos into one image (think a body with a hole in the face on top of a picture of a different person's face). The top image has some semi-transparent pixels and some fully transparent pixels and I want to overlay it on top of a solid image.</p> <p>Here's what I'm doing: I have a Context with the right size and I draw the bottom image on it, without any alpha (faceImage). On top of that I draw an image that has a transparent hole in it, with various levels of transparencies (coverImage): </p> <pre><code>UIGraphicsBeginImageContext(view.bounds.size); [faceImage drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:1]; [coverImage drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:1]; UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); </code></pre> <p>The results in the final image are quite unexpected:</p> <p>In pixels where the <strong>top image has no transparency</strong> the final image is saved properly and shows the pixel from the top image. (<strong>OK</strong>)</p> <p>In pixels where the <strong>top image has full transparency</strong> the final image is saved properly and shows the pixel from the bottom image. (<strong>OK</strong>)</p> <p>In pixels where the <strong>top image has semi-transparent pixels and the brightness is very light</strong> (the brightness of the final pixel) I suddenly get entirely <strong>transparent pixels</strong> (instead of a final pixel with no transparency that's a blend between the top pixel and the bottom pixel). (WTF?)</p> <p>In the image below you can see weird blotches of white. Those are the pixels that became entirely transparent pixels (you see the white background through them): <img src="https://i.stack.imgur.com/B4zaN.png" alt="The combined image with the weird transparent pixels"></p> <p>This is the image that I'm putting on top:</p> <p><img src="https://i.stack.imgur.com/cVAiV.png" alt="The top image with the semi transparent pixels"></p> <p>This is the face image on the bottom:</p> <p><img src="https://i.stack.imgur.com/4039z.png" alt="The face image on the bottom"></p> <p>Any ideas what could be causing this?</p> <p>TIA</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload