Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating mask with CGImageMaskCreate is all black (iphone)
    primarykey
    data
    text
    <p>I'm trying to create an image mask that from a composite of two existing images.</p> <p>First I start with creating the composite which consists of a small image that is the masking image, and a larger image which is the same size as the background:</p> <pre><code>UIImage * BaseTextureImage = [UIImage imageNamed:@"background.png"]; UIImage * MaskImage = [UIImage imageNamed:@"my_mask.jpg"]; UIImage * ShapesBase = [UIImage imageNamed:@"largerimage.jpg"]; UIImage * MaskImageFull; CGSize finalSize = CGSizeMake(480.0, 320.0); UIGraphicsBeginImageContext(finalSize); [ShapesBase drawInRect:CGRectMake(0, 0, 480, 320)]; [MaskImage drawInRect:CGRectMake(150, 50, 250, 250)]; MaskImageFull = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); </code></pre> <p>I can output this UIImage (MaskImageFull) and it looks right, it is a fullsize background size and it is a white background with my mask object in black, in the right place on the screen.</p> <p>I then pass the MaskImageFull UIImage through this:</p> <pre><code>CGImageRef maskRef = [maskImage CGImage]; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([image CGImage], mask); UIImage* retImage= [UIImage imageWithCGImage:masked]; </code></pre> <p>The problem is that the retImage is all black. If I send a pre-made UIImage in as the mask it works fine, it is just when I try to make it from multiple images that it breaks.</p> <p>I thought it was a colorspace thing but couldn't seem to fix it. Any help is much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    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