Created
June 15, 2019 08:29
-
-
Save addr010/d805b81959a34299b230dd4bdd14477f to your computer and use it in GitHub Desktop.
Create Jpeg data from CGImage in Xamarin C#
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
static NSData JpegData(this CGImage cgImage, float compressionQuality) | |
{ | |
var data = NSMutableData.Create(); | |
var idst = CGImageDestination.Create(data, "UTTypeJPEG", 1, null); | |
if (idst != null) | |
{ | |
var props = NSDictionary.FromObjectsAndKeys( | |
new[] { NSNumber.FromFloat(compressionQuality) }, | |
new[] { CGImageDestinationOptionsKeys.LossyCompressionQuality } | |
); | |
idst.AddImage(cgImage, props); | |
idst.Close(); | |
return NSData.FromData(data); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment