How To Read RBG-Pixel values from CGImage in ios

2019-08-30 07:41发布

问题:

How I can Read the RGB-Pixel by Pixel values from CGImagea also after how to assign it to UIImage

回答1:

To read RGB pixel values with MonoTouch you can use the code posted in the answer to the following post (works fine for me):

Retrieving a pixel alpha value for a UIImage (MonoTouch)

You can also find the following post useful:

Transparent PNGs in Monotouch for iOS

And here is a link to a working implementation of mine of a convolution filter, that reads and demultiplies the pixel's rgb values (on iOS all images with alpha channel are stored in a premultiplied-alpha format):

How to Optimize this Image convolution filter Method in MonoTouch?

Remember that reading pixel values is very slow, even if you use the trick to create a bitmap context of only 1x1 pixels.



回答2:

according this link Bitmap is used to work with images defined by pixel data.

yourimage= new Bitmap(@"image address", true);

    int x, y;

    // Loop through the images
    for(x=0; x<yourimage.Width; x++)
    {
        for(y=0; y<yourimage.Height; y++)
        {
            //Get Pixel Color
            Color pixelColor = image1.GetPixel(x, y);
            Color yourColor = Color.FromArgb(pixelColor.R, 0, 0);
            //Set Pixel Color
            yourimage.SetPixel(x, y, yourColor );