iphone - UIImage with mask/alpha weirdness -


i'm experiencing weirdness uiimage. basically, i'm:

  • loading image photo album uiimage.
  • creating mask consists of black ellipse on white.
  • using cgimagecreatewithmask cut out portion of original uiimage.
  • display resulting uiimage onscreen , looks correct.
  • save out same uiimage png.

but when @ resulting png file, alpha reversed!

any ideas out there?

here's code:

// originalimage uiimage loaded photo album  cgimageref cgimage = [originalimage cgimage];  // make sure has alpha channel     cgimageref shrunk1 = copyimageandaddalphachannel(shrunk);  // create oval mask cgcolorspaceref colorspace = cgcolorspacecreatedevicergb(); cgcontextref oc = cgbitmapcontextcreate(null, desiredwidth, desiredheight,                                                 8,                                                 desiredwidth * 4,                                                 colorspace,                                                 kcgimagealphanoneskiplast); // on white bgd cgcontextsetrgbfillcolor(oc, 1.0, 1.0, 1.0, 1.0); cgcontextfillrect(oc, cgrectmake(0, 0, desiredwidth, desiredheight));  // black oval cgcontextsetrgbfillcolor(oc, 0.0, 0.0, 0.0, 1.0); cgcontextfillellipseinrect(oc, cgrectmake(0, 0, desiredwidth, desiredheight)); cgimageref mask1 = cgbitmapcontextcreateimage(oc);  cgimageref mask = cgimagemaskcreate(cgimagegetwidth(mask1), cgimagegetheight(mask1),     cgimagegetbitspercomponent(mask1), cgimagegetbitsperpixel(mask1), cgimagegetbytesperrow(mask1), cgimagegetdataprovider(mask1), null, null);  // cut out original image oval mask cgimageref shrunk2 = cgimagecreatewithmask(shrunk1, mask);  // save uiimage *final = [uiimage imagewithcgimage:shrunk2]; nsstring *s = [self getdatetimefilename]; nsstring *pngpath = [nshomedirectory() stringbyappendingformat:@"/documents/%@.png", s]; [uiimagepngrepresentation(final) writetofile:pngpath atomically:yes];  cgimagerelease(shrunk2); cgimagerelease(mask); cgimagerelease(mask1); cgcontextrelease(oc); cgcolorspacerelease(colorspace); 

any , appreciated. thanks!


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -