Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
public byte[] MakeGrayScale(byte[] imageAsBytes)
{
UIImage image = ImageFromByteArray(imageAsBytes);
var height = image.Size.Height;
var width = image.Size.Width;
var imageRect = new CGRect(0, 0, width, height);
using (CGBitmapContext context = new CGBitmapContext(IntPtr.Zero,
(int)width, (int)height, 8,
0, CGColorSpace.CreateDeviceGray(),
CGImageAlphaInfo.None))
{
// draw the image
context.DrawImage(imageRect, image.CGImage);
UIKit.UIImage copyImage = UIKit.UIImage.FromImage(context.ToImage(), 0, image.Orientation);
// save the image as a jpeg
return copyImage.AsJPEG().ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment