Created
May 26, 2016 19:09
-
-
Save rasmuschristensen/db61ca59c06fabb9201f60c7413646a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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