Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Image Mask from Grayscale JPEG



OK... I'm trying to do something I've never done before, draw with an image mask. It's turning out to be more challenging than I would have expected.

I have a grayscale JPEG (a lovely, blurry circle) and I want to use that as an Image Mask.  Can load the file's pixel data into a CGImage, through ImageIO, but that creates an Image (i.e. a CGImage with a color space) and not an image mask (which I gather is a CGImage with no color space).

What I don't know is what is the best way to convert the Image into an Image Mask.

The most obvious way to do what I want, I believe, is going to be to create a grayscale bitmap context, draw the image I want to use as my mask into that bitmap, then use CGCreateImageMask to create a mask from the pixels.  That seems like a very round-about way to create a mask from an image.

I tried using CGImageCreateWithMask and passed it the image I want to mask, and my masking image.  Unfortunately the call always fails.

At one point, I thought it was because the file is tagged with the Generic Gray color space  and the documentation says that CGImageCreateWithMask requires the image you use as a mask to be Device Gray.  To work around this, I tried using CGImageCreateCopyWithColorSpace to create a copy of my mask data in the device gray space... but CGImageCreateWithMask still fails.  (no explanation given... even if I use the debug library prefix version). :-(

Is there an easy way to transform a grayscale image into an image mask without having to draw it in a buffer first?

Scott



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.