How To Read RBG-Pixel values from CGImage in ios

大憨熊 提交于 2019-12-11 17:46:34

问题


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 );


来源:https://stackoverflow.com/questions/11132410/how-to-read-rbg-pixel-values-from-cgimage-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!