• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CGImage masking via CGCreateImageWithMask getting odd results
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGImage masking via CGCreateImageWithMask getting odd results


  • Subject: Re: CGImage masking via CGCreateImageWithMask getting odd results
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Sun, 10 Aug 2008 16:34:41 +0200


Le 10 août 08 à 06:08, Nick Veys a écrit :

I'm getting some interesting results with an image mask I'm trying to
apply.  I'm trying to vignette away the edges of some small images and
instead of getting transparency behind them, I'm getting the black
(presumably from the mask).

I'm simply calling CGImageCreateWithMask(image, mask) with two
CGImageRefs, image is 'image.png', attached.  mask is 'mask.png',
attached.  The result I'm seeing is 'result.png', also attached.
Instead of seeing through, I see black (the background is white...)!
Argh.  I've played with the views behind it and set their colors to
all kinds of fun things and I never see that color, just the black
from the mask.  Am I completely misinterpreting what the mask is?
From the docs it says if the mask is an image, which it is via
verification with CGImageIsMask(), it uses the grayscale as an alpha
value, so it would effectively fade the corners of my images into the
layer behind it.

Even stranger, if I go and put a few lines across the image, say a
solid black line, a 50% gray line, and a 25% gray line, I see on the
final composited image a solid black line, a 50% transparent line and
a 25% transparent line ('lines.png', attached).  So there seems to be
some logic behind the operation that's occurring, it's just definitely
not what I'm looking for.

Any info is appreciated!

Have a look at the Core Graphics doc.

http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_images/chapter_12_section_6.html

There ii some sample image to explain how mask works.
First, you have to create a mask using CGImageMaskCreate().
This function look complex, but if you already have a CGImage, you can convert it into a mask using this call:
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(image), CGImageGetHeight(image),
CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image),
CGImageGetBytesPerRow(image), CGImageGetDataProvider(image), NULL, false);


A mask is an image where white describe zone that should be ignored, and black zone that will be display (the opposite of your mask in fact).



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >CGImage masking via CGCreateImageWithMask getting odd results (From: "Nick Veys" <email@hidden>)

  • Prev by Date: Re: Core Data, dynamic accessors and compiler warnings
  • Next by Date: Re: Controlling line-breaking in a text view
  • Previous by thread: CGImage masking via CGCreateImageWithMask getting odd results
  • Next by thread: Accessing member variables from another thread crashes
  • Index(es):
    • Date
    • Thread