iOS Guides | Samples

ImageIO.CGImageDestination Class

Use this class to save images and have detailed control over how the images are saved.

See Also: CGImageDestination

Syntax

public class CGImageDestination : INativeObject, IDisposable

Remarks

You create new instances of CGImageDestination by calling one of the factory methods.   There are three versions of it:

  • Storing the generated image into a file pointed to by an NSUrl.
  • Storing the generated image into an NSMutableData
  • Storing the generated image into a CGDataConsumer

In the classic API, those methods were called FromUrl, FromData and Create respectively.   But this naming was incorrect, as it did not really create an image destination from a url, or a data.  In the Unified API, they have all been turned into CGImageDestination.Create methods.

Once you have created the image, you can call CGImageDestination.AddImage or CGImageDestination.AddImageAndMetadata to add one or more images.   

To write out the image, you must call the CGImageDestination.Close method.   

C# Example

// The following example shows how to store an image into
// an in-memory PNG file stored inside an NSData.

NSData ImageToPng (CGImage image)
{
   var storage = new NSMutableData ()
   var dest = CGImageDestination.Create (storage, MobileCoreServices.UTType.PNG, imageCount: 1);
   dest.AddImage (image);
   dest.Close (); 
   return storage;
}

Requirements

Namespace: ImageIO
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0

The members of ImageIO.CGImageDestination are listed below.

See Also: Object

Public Properties

[read-only]
HandleIntPtr. Handle (pointer) to the unmanaged object representation.
[read-only]
static
TypeIdentifiersString[].

Public Methods

Protected Methods

Dispose(Boolean)
Releases the resources used by the CGImageDestination object.