Working with picture color codes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.