Process picture Color-(uiimage*) Grayscale: (uiimage*) animage type: (int) type{cgimageref imageref = animage.cgimage; size_t width = cgimagegetwidth (imageref); size_t height = cgimagegetheight (imageref); size_t bitspercomponent = cgimagegetbitspercomponent (imageref); size_t bitsperpixel = Cgimagegetbitsperpixel (imageref); size_t Bytesperrow = Cgimagegetbytesperrow (imageref); Cgcolorspaceref colorspace = Cgimagegetcolorspace (imageref); Cgbitmapinfo bitmapinfo = Cgimagegetbitmapinfo (imageref); BOOL Shouldinterpolate = Cgimagegetshouldinterpolate (imageref); Cgcolorrenderingintent Intent = cgimagegetrenderingintent (IMAGEREF); Cgdataproviderref Dataprovider = Cgimagegetdataprovider (imageref); Cfdataref data = Cgdataprovidercopydata (Dataprovider); UInt8 *buffer = (uint8*) cfdatagetbyteptr (data); Nsuinteger x, y; for (y = 0, y < height; y++) {for (x = 0; x < width; + x + +) {UInt8 *tmp; TMP = buffer + y * bytesperrow + x * 4; UInt8 Red,green,blue; Red = * (tmp + 0); Green = * (tmp + 1); Blue = * (tmp + 2); UInt8 brightness; Switch (type) {Case 1:brightness = (* * Red + * green + 151 * blue)/256; * (tmp + 0) = brightness; * (tmp + 1) = brightness; * (tmp + 2) = brightness; Break Case 2: * (tmp + 0) = red; * (tmp + 1) = green * 0.7; * (tmp + 2) = blue * 0.4; Break Case 3: * (tmp + 0) = 255-red; * (tmp + 1) = 255-green; * (tmp + 2) = 255-blue; Break Default: * (tmp + 0) = red; * (tmp + 1) = green; * (tmp + 2) = blue; Break }}} CfdatarEF Effecteddata = cfdatacreate (NULL, buffer, cfdatagetlength (data)); Cgdataproviderref Effecteddataprovider = Cgdataprovidercreatewithcfdata (Effecteddata); Cgimageref effectedcgimage = cgimagecreate (width, height, Bitspercomponent, BitsPerPixel, Bytesperrow, CO Lorspace, Bitmapinfo, Effecteddataprovider, NULL, shouldinterpolate, intent) ; UIImage *effectedimage = [[UIImage alloc] initwithcgimage:effectedcgimage]; Cgimagerelease (Effectedcgimage); Cfrelease (Effecteddataprovider); Cfrelease (Effecteddata); Cfrelease (data); return effectedimage;}
Working with picture color codes