class MotionAL::Representation

A wrapper of ALRepresentation class.

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.

And added some convinience methods.

Attributes

al_asset_representation[R]
asset[R]

Public Class Methods

new(asset, al_asset_representation) click to toggle source

@param asset [MotionAL::Asset] A parent asset. @param al_asset_representation [ALAssetRepresentation] An instance of ALAssetRepresentation.

# File lib/motional/representation.rb, line 16
def initialize(asset, al_asset_representation)
  @asset = asset
  @al_asset_representation = al_asset_representation
end

Private Class Methods

make_wrapper_for_method(method_name, type_of_return) click to toggle source

wrapper for method @!macro [attach] make_wrapper

The representation's $1

@method $1
@return [$2]
# File lib/motional/representation.rb, line 85
def make_wrapper_for_method(method_name, type_of_return)
  define_method(method_name) do 
    @al_asset_representation.send(method_name)
  end
end

Public Instance Methods

cg_image()
cg_image_with_options(options) click to toggle source

@param options [Hash] described for CGImageSourceCreateWithData or CGImageSourceCreateWithURL. @return [CGImageRef] A full resolution CGImage of the representation.

# File lib/motional/representation.rb, line 39
def cg_image_with_options(options)
  @al_asset_representation.CGImageWithOptions(options)
end
data() click to toggle source

return a NSConcreteData(kind of NSData) object for the representation file.

support only jpeg and png.

@return [NSConcreteData]

# File lib/motional/representation.rb, line 26
def data
  ui_image = UIImage.imageWithCGImage(self.cg_image)
  if self.filename =~ /.jpe?g$/i
    NSData.alloc.initWithData(UIImageJPEGRepresentation(ui_image, 0.0))
  elsif self.filename =~ /.png$/i
    NSData.alloc.initWithData(UIImagePNGRepresentation(ui_image))
  else
    nil
  end
end
full_resolution_image() click to toggle source

A CGImage of the representation.

@return [CGImageRef] @return [nil] When the representation has no CGImage.

# File lib/motional/representation.rb, line 56
def full_resolution_image
  @al_asset_representation.fullResolutionImage
end
Also aliased as: cg_image
full_screen_image() click to toggle source

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

@return [CGImageRef] @return [nil] When the representation has no CGImage.

# File lib/motional/representation.rb, line 65
def full_screen_image
  @al_asset_representation.fullScreenImage
end
metadata() click to toggle source

Metadata of the representation.

@return [Hash] A multidimensional hash. @return [nil] When the representation has no metadata or incompatible metadata.

# File lib/motional/representation.rb, line 73
def metadata
  @al_asset_representation.metadata
end
orientation() click to toggle source

The orientation of the representation.

@return [Symbol] :up, :down :left, :right, :up_mirrored, :down_mirrored, :left_mirrored or :right_mirrored

@see MotionAL.asset_orientations

# File lib/motional/representation.rb, line 48
def orientation
  MotionAL.asset_orientations.key(@al_asset.valueForProperty(ALAssetPropertyOrientation))
end