Forum Xamarin Xamarin.Android

How can I get the R, G and B channels of an image using xamarin?

How can I get the pixel values of R, G and B channels in the xamarin? I am using this code but it is giving me error.

int i, j;
        Bitmap image = bitmapimage;
        int width = image.Width;
        int height = image.Height;
            byte[,,] rgb = new byte[3, height, width];
            for (i = 0; i < height; i++)

            for (j = 0; j < width; j++)

                rgb[0, i, j] = image.GetPixel(j, i).R;
                    rgb[1, i, j] = image.GetPixel(j, i).G;
                    rgb[2, i, j] = image.GetPixel(j, i).B;
            MWNumericArray narr = new MWNumericArray();
            narr = rgb;

            Salt obj = new Salt();
            MWArray u = obj.classification(narr);

But when i used the same code in c# windows and c# web application it works fine. Please help me where I am wrong.



  • RofiqSetiawanRofiqSetiawan USMember ✭✭✭

    Try something like these:

    var x = 1;
    var y = 1;
    int colour = bmp.GetPixel(x, y);
    int red = Color.GetRedComponent(colour);
    int blue = Color.GetBlueComponent(colour);
    int green = Color.GetGreenComponent(colour);
    int alpha = Color.GetAlphaComponent(colour);
Sign In or Register to comment.