public void FromData_BadITU() { using (NSMutableData destData = new NSMutableData()) { #if XAMCORE_2_0 // FromData => Create Assert.Null(CGImageDestination.Create(destData, BadUti, 1), "FromData-1"); Assert.Null(CGImageDestination.Create(destData, BadUti, 1, new CGImageDestinationOptions()), "FromData-2"); #else Assert.Null(CGImageDestination.FromData(destData, BadUti, 1), "FromData-1"); Assert.Null(CGImageDestination.FromData(destData, BadUti, 1, new CGImageDestinationOptions()), "FromData-2"); #endif } }
public void AddImage() { string file = Path.Combine(NSBundle.MainBundle.ResourcePath, "basn3p08.png"); using (NSMutableData destData = new NSMutableData()) using (var uiimg = UIImage.FromFile(file)) using (var img = uiimg.CGImage) #if XAMCORE_2_0 // FromData => Create using (var id = CGImageDestination.Create(destData, GoodUti, 1)) { #else using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) { #endif id.AddImage(img, (NSDictionary)null); } }
public void CopyImageSource() { TestRuntime.AssertXcodeVersion(5, 0); using (NSData data = NSData.FromFile("xamarin2.png")) using (var source = CGImageSource.FromData(data)) using (NSMutableData destData = new NSMutableData()) #if XAMCORE_2_0 // FromData => Create using (var id = CGImageDestination.Create(destData, GoodUti, 1)) { #else using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) { #endif NSError err; // testing that null is allowed (no crash) so the fact that is return false and an error does not matter Assert.False(id.CopyImageSource(source, (NSDictionary)null, out err), "CopyImageSource"); Assert.NotNull(err, "NSError"); } }
public void AddImageAndMetadata() { TestRuntime.AssertXcodeVersion(5, 0); string file = Path.Combine(NSBundle.MainBundle.ResourcePath, "basn3p08.png"); using (NSMutableData destData = new NSMutableData()) using (var uiimg = UIImage.FromFile(file)) using (var img = uiimg.CGImage) #if XAMCORE_2_0 // FromData => Create using (var id = CGImageDestination.Create(destData, GoodUti, 1)) #else using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) #endif using (var mutable = new CGMutableImageMetadata()) { id.AddImageAndMetadata(img, mutable, (NSDictionary)null); } }
public void FromData_GoodITU() { using (NSMutableData destData = new NSMutableData()) { #if XAMCORE_2_0 // FromData => Create using (var id = CGImageDestination.Create(destData, GoodUti, 1)) { #else using (var id = CGImageDestination.FromData(destData, GoodUti, 1)) { #endif Assert.That(id.Handle, Is.Not.EqualTo(IntPtr.Zero), "handle-1"); } #if XAMCORE_2_0 // FromData => Create using (var id = CGImageDestination.Create(destData, GoodUti, 1, new CGImageDestinationOptions())) { #else using (var id = CGImageDestination.FromData(destData, GoodUti, 1, new CGImageDestinationOptions())) { #endif Assert.That(id.Handle, Is.Not.EqualTo(IntPtr.Zero), "handle-2"); } } }
public new void Save(Stream stream, ImageFormat format) { if (stream == null) { throw new ArgumentNullException("stream"); } using (var imageData = new NSMutableData()) { #if !XAMARINMAC using (var dest = CGImageDestination.FromData(imageData, GetTypeIdentifier(format), frameCount)) #else using (var dest = CGImageDestination.Create(imageData, GetTypeIdentifier(format), frameCount)) #endif Save(dest); using (var ms = imageData.AsStream()) ms.CopyTo(stream); } }