ALAssetRepresentation Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AssetsLibrary.framework
Availability
Available in iOS 4.0 and later.
Declared in
ALAssetRepresentation.h
Related sample code

Overview

An ALAssetRepresentation object encapsulates one of the representations of a given ALAsset object.

A given asset in the library may have more than one representation. For example, if a camera provides RAW and JPEG versions of an image, the resulting asset will have two representations—one for the RAW file and one for the JPEG file.

Tasks

Getting Image Representations

Getting Image Attributes

Getting Raw Data

Getting Metadata

Getting an URL

Instance Methods

CGImageWithOptions:

Returns a full resolution CGImage of the representation.

- (CGImageRef)CGImageWithOptions:(NSDictionary *)options
Parameters
options

A dictionary of options as described for CGImageSourceCreateWithData or CGImageSourceCreateWithURL.

Return Value

A full resolution CGImage of the representation.

Discussion

This method provides a convenient way to obtain a CGImage representation of an asset. This method returns the biggest, best representation available, unadjusted in any way.

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetRepresentation.h

dimensions

Returns the representation’s dimensions.

- (CGSize)dimensions
Return Value

The representation’s dimensions.

Discussion

If the representation doesn’t have valid dimensions, this method will return CGSizeZero.

Availability
  • Available in iOS 5.1 and later.
Declared In
ALAssetRepresentation.h

filename

Returns a string representing the filename of the representation on disk.

- (NSString *)filename
Return Value

A string representing the filename of the representation on disk.

Discussion

For representations synced from iTunes, this will be the filename of the representation on the host.

Availability
  • Available in iOS 5.0 and later.
Declared In
ALAssetRepresentation.h

fullResolutionImage

Returns a CGImage representation of the asset.

- (CGImageRef)fullResolutionImage
Return Value

A CGImage representation of the asset, or NULL if a CGImage representation could not be generated.

Discussion

This method returns the biggest, best representation available, unadjusted in any way.

To create a correctly-rotated UIImage object from the CGImage, you use imageWithCGImage:scale:orientation: or initWithCGImage:scale:orientation:, passing the values of orientation and scale.

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetRepresentation.h

fullScreenImage

Returns a CGImage of the representation that is appropriate for displaying full screen.

- (CGImageRef)fullScreenImage
Return Value

A CGImage of the representation that is appropriate for displaying full screen, or NULL if a CGImage representation could not be generated.

Discussion

The dimensions of the image are dependent on the device your application is running on; the dimensions may not, however, exactly match the dimensions of the screen.

In iOS 5 and later, this method returns a fully cropped, rotated, and adjusted image—exactly as a user would see in Photos or in the image picker.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
ALAssetRepresentation.h

getBytes:fromOffset:length:error:

Copies a specified range of bytes into a given buffer.

- (NSUInteger)getBytes:(uint8_t *)buffer fromOffset:(long long)offset length:(NSUInteger)length error:(NSError **)error
Parameters
buffer

A buffer into which to copy the data.

You typically use size to allocate a buffer of the right size.

offset

The number of bytes from the beginning of the file to start copying.

length

The number of bytes to copy.

error

If an error occurs, upon return contains an NSError object that describes the problem.

Pass NULL if you do not want error information.

Return Value

The number of bytes actually written to buffer. The number of bytes read will be less than the requested range if the range exceeds the file's size. If an error occurs, returns 0.

Discussion

This method returns the biggest, best representation available, unadjusted in any way.

Availability
  • Available in iOS 4.0 and later.
See Also
Related Sample Code
Declared In
ALAssetRepresentation.h

metadata

Returns a dictionary of dictionaries of metadata for the representation.

- (NSDictionary *)metadata
Return Value

A dictionary of dictionaries of metadata for the representation. Returns nil if the representation is one that the system cannot interpret.

Discussion

The returned dictionary holds the same values that would be returned by CGImageSourceCopyPropertiesAtIndex.

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetRepresentation.h

orientation

Returns the representation’s orientation.

- (ALAssetOrientation)orientation
Return Value

The representation’s orientation. For a list of possible values, see ALAssetOrientation.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
ALAssetRepresentation.h

scale

Returns the representation’s scale.

- (float)scale
Return Value

The representation’s scale.

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetRepresentation.h

size

Returns the size in bytes of the file for the representation.

- (long long)size
Return Value

The size in bytes of the file for the representation.

Discussion

You typically use this method to allocate a buffer of the right size for getBytes:fromOffset:length:error:.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
ALAssetRepresentation.h

url

Returns a persistent URL uniquely identifying the representation.

- (NSURL *)url
Return Value

A persistent URL uniquely identifying the representation.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
ALAssetRepresentation.h

UTI

Returns the representation's UTI.

- (NSString *)UTI
Return Value

The representation's UTI

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetRepresentation.h