Skip to content

Instantly share code, notes, and snippets.

@rasmuschristensen
Created May 26, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasmuschristensen/db61ca59c06fabb9201f60c7413646a7 to your computer and use it in GitHub Desktop.
Save rasmuschristensen/db61ca59c06fabb9201f60c7413646a7 to your computer and use it in GitHub Desktop.
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