In my iOS application I can show a image in UIImageView, then I want to get the pixel's RGB value from the UIImageView.
How do I do that?
This is Xamarin.iOS project in C#. Thanks for any hints.
In my iOS application I can show a image in UIImageView, then I want to get the pixel's RGB value from the UIImageView.
How do I do that?
This is Xamarin.iOS project in C#. Thanks for any hints.
In order to get RGB value of a pixel in UIImage, you have to work with CGImage actually.
So you have UIImageView which uses UIImage. To get CGImage you have to use UIImage.CGImage
property and then use any of the available solutions.
For example, this one
Alternative options: How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?
Thanks for Alex Sorokoletov, Now ,I have a solution for my project , It is like this:
nint pixLen = imageWidth * imageHeigh;
nint count = pixLen * 4 ;
byte[] newImageArr = new byte[count];
using (var context = new CGBitmapContext(newImageArr, imageWidth, imageHeigh,
bitsPerComponent, bytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedLast))
{
RectangleF imageRec = new RectangleF(0, 0, imageWidth, imageHeigh);
context.DrawImage(imageRec, myCgImage);
for (int i = 0; i < count; i = i+4)
{
float clorRed = (newImageArr[i]) ;
float clorGreen = (newImageArr[i + 1]) ;
float clorBlue = (newImageArr[i + 2]) ;
}
}