uiimage - Iphone - Masking JPG images -
i coding jigsaw puzzle , need mask images create puzzle pieces.
i using pictures online server , *.jpg. when mask them, area should transparent black.
can add alpha channel programmatically? if yes, can show me how?
thanks lot, andrei
i found answer:
cgimageref imageref = self.cgimage; size_t width = cgimagegetwidth(imageref); size_t height = cgimagegetheight(imageref); // bitspercomponent , bitmapinfo values hard-coded prevent "unsupported parameter combination" error cgcontextref offscreencontext = cgbitmapcontextcreate(null, width, height, 8, 0, cgimagegetcolorspace(imageref), kcgbitmapbyteorderdefault | kcgimagealphapremultipliedfirst); // draw image context , retrieve new image, have alpha layer cgcontextdrawimage(offscreencontext, cgrectmake(0, 0, width, height), imageref); cgimageref imagerefwithalpha = cgbitmapcontextcreateimage(offscreencontext); uiimage *imagewithalpha = [uiimage imagewithcgimage:imagerefwithalpha]; // clean cgcontextrelease(offscreencontext); cgimagerelease(imagerefwithalpha); return imagewithalpha;
Comments
Post a Comment