RRAvatar

Objective-C

@interface RRAvatar : NSObject

Swift

class RRAvatar : NSObject

An object that models a person and all related metadata for virtual try-on. Further, it provides methods for reading and writing avatars from/to different sources as well as other convenience methods. To display an avatar a RRAvatarRenderable is needed together with a RRGLRenderView. The RRAvatarCaptureView can be used to capture a new avatar using the phones camera. An existing avatar can be edited using the RRAvatarEditorView.

  • Returns the avatar data encoded as a byte buffer. This encoding is useful when transferring avatars via binary data channels.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSData *_Nonnull byteBuffer;

    Swift

    var byteBuffer: Data { get }
  • Creates an avatar from a byte buffer. This encoding is useful when transferring avatars via binary data channels.

    Declaration

    Objective-C

    + (RRAvatar *_Nullable)avatarFromByteBuffer:(NSData *_Nonnull)byteBuffer;

    Swift

    /*not inherited*/ init?(fromByteBuffer byteBuffer: Data)

    Parameters

    byteBuffer

    Avatar data as byte buffer.

    Return Value

    An instance of the RRAvatar class on success, nil otherwise.

  • Creates an avatar from a .avatar file. The content of a .avatar file is binary and is equivalent to the byte buffer encoding that can be obtained using the byteBuffer property

    Declaration

    Objective-C

    + (RRAvatar *_Nullable)avatarFromFile:(NSString *_Nonnull)path;

    Swift

    /*not inherited*/ init?(fromFile path: String)

    Parameters

    path

    Path to the avatar file.

    Return Value

    An instance of the RRAvatar class on success, nil otherwise.

  • Returns a thumbnail showing the avatars face and upper body with the given size. The avatar is fitted into the specified size without distorting the avatar’s image. This function is intended for rendering thumbnails of arbitrary size needed for GUI purposes.

    Declaration

    Objective-C

    - (RRImage *_Nullable)createThumbnail:(CGSize)size
                           applyAlphaMask:(BOOL)applyAlphaMask
                         didFailWithError:(NSError *_Nullable *_Nullable)error;

    Swift

    func createThumbnail(_ size: CGSize, applyAlphaMask: Bool) throws -> RRImage

    Parameters

    size

    Target size of the thumbnail.

    applyAlphaMask

    This parameter defines if the thumbnail should be transparent around the avatar or if it should contain the background of the color image. Be aware that artificially generated avatars like head avatars will not include any reasonable background. Therefore setting applyAlphaMask to YES is the safer option to get consistent quality for all possible avatars.

    error

    An optional pointer to an NSError pointer. When this method fails, it will set an NSError instance to this pointer if provided.

    Return Value

    A thumbnail with the specified size. This method returns nil if an error occurs.

  • Deprecated

    Returns a thumbnail showing the avatars face and upper body with the given size. The avatar is fitted into the specified size without distorting the avatar’s image. This function is intended for rendering thumbnails of arbitrary size needed for GUI purposes. This method will always render the avatar image without any transparencies. Be aware that artificially generated avatars like head avatars will not include any reasonable background. This can easily lead to non-appealing thumbnails for artificially generated avatars.

    Declaration

    Objective-C

    - (RRImage *_Nullable)createThumbnail:(CGSize)size
                         didFailWithError:(NSError *_Nullable *_Nullable)error;

    Swift

    func createThumbnail(_ size: CGSize) throws -> RRImage

    Parameters

    size

    Target size of the thumbnail.

    error

    An optional pointer to an NSError pointer. When this method fails, it will set an NSError instance to this pointer if provided.

    Return Value

    A thumbnail with the specified size. This method returns nil if an error occurs.

  • Brightness adjustment factor which is used when rendering as RRAvatarRenderable. This factor can be used to establish visual coherence when rendering the avatar in front of a different background than the original one. The value should be in the range [-1 1] where zero means no change of the avatar’s brightness and a smaller value means lower brightness

    Declaration

    Objective-C

    @property (nonatomic) CGFloat brightnessOffset;

    Swift

    var brightnessOffset: CGFloat { get set }
  • Saturation adjustment factor which is used when rendering as RRAvatarRenderable. This factor can be used to establish visual coherence when rendering the avatar in front of a different background than the original one. The value should be in the range [-1 1] where zero means no change of the avatar’s saturation and a smaller value means lower saturation

    Declaration

    Objective-C

    @property (nonatomic) CGFloat saturationOffset;

    Swift

    var saturationOffset: CGFloat { get set }
  • Returns whether or not the avatar contains alpha matting information. This information is need when rendering an avatar within a “Scene” or with a custom background.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL hasAlphaMatting;

    Swift

    var hasAlphaMatting: Bool { get }
  • Returns whether or not the avatar is fully visible in the image.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL isFullyVisible;

    Swift

    var isFullyVisible: Bool { get }
  • The avatar’s color image.

    Declaration

    Objective-C

    @property (nonatomic, readonly) RRImage *_Nullable color;

    Swift

    var color: RRImage? { get }
  • The avatar’s single channel mask image

    Declaration

    Objective-C

    @property (nonatomic, readonly) RRImage *_Nullable mask;

    Swift

    var mask: RRImage? { get }