Mailing Lists: Apple Mailing Lists

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

Re: Difficulty masking an image with another image




On May 11, 2006, at 7:28 PM, Peter Bates wrote:

HI folks,

I'm just getting my feet wet with Quartz 2D and built a small app to try out some functions.  The following code doesn't behave as I expected.  Specifically the asterisked line below leaves maskedImage as nil.  Either MyImage or aGrayScaleImage will display correctly.  Any help appreciated.

Thanks,
Pete

An image mask and an image are not necessarily interchangeable.  More likely than not, your grayscale image is actually coming in as an RGB image where it needs to be 1, 2, 4, or 8 bit greyscale (DeviceGray).  You can check this by asking the image you are using as your mask for it's color space.


You might also be able to get away with CGImageCreateCopyWithColorSpace IF the image doesn't have any alpha (I don't believe JPEG images do). Or you can redraw the masking image into a CGBitmapContext with the appropriate color characteristics (8 bit per pixel, DeviceGray) and then use CGImageMaskCreate to create an image mask from the resulting bitmap.  

(
Also, if you are on Tiger you could also simplify your code a bit by using Image I/O and CGImageSourceCreateWithURL:

NSURL *k9TeethImageURL = [NSURL fileURLWithPath:  [[NSBundle mainBundle] pathForImageResource:@"MyImage.png"]];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef) k9TeethImageURL);
CGImageRef k9TheethImage = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
CFRelease(imageSource);

I typed the code sample into Mail so it may take a little finessing
)

As someone new to Quartz, may I suggest my introductory text:

<http://www.amazon.com/gp/product/0321336631>

Or David Gelphman's more comprehensive tome:

<http://www.amazon.com/gp/product/0123694736>

Both of which cover masking of images at their respective levels.

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

References: 
 >Difficulty masking an image with another image (From: Peter Bates <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.