PhotoEditRenderer

@available(iOS 9.0, *)
@objcMembers
@objc(PESDKPhotoEditRenderer)
open class PhotoEditRenderer : NSObject

A PhotoEditRenderer takes a CIImage and a PhotoEditModel as input and takes care of applying all necessary effects and filters to the image. The output image can then be rendered into an EAGLContext or converted into a CGImage instance.

  • The input image.

    Declaration

    Swift

    open var originalImage: CIImage? { get set }
  • The photo edit model that describes all effects that should be applied to the input image.

    Declaration

    Swift

    open var photoEditModel: PhotoEditModel
  • The render mode describes which effects should be applied to the input image.

    Declaration

    Swift

    open var renderMode: <<error type>> { get set }
  • The asset manager that is associated with this renderer. It is used to fetch the resources for sprites like stickers, brush and frames.

    Declaration

    Swift

    open var assetManager: AssetManager?
  • A CIImage instance with all effects and filters applied to it.

    Declaration

    Swift

    open var outputImage: CIImage { get }
  • The size of the output image.

    Declaration

    Swift

    open var outputImageSize: CGSize { get }
  • Invalidates the cache. You can call this prior to rendering to force a complete rerender.

    Declaration

    Swift

    open func invalidateCache()
  • Applies all necessary filters and effects to the input image and converts it to an instance of CGImage.

    Declaration

    Swift

    open func newOutputImage() -> CGImage

    Return Value

    A newly created instance of CGImage.

  • Same as newOutputImage() but asynchronously.

    Declaration

    Swift

    @objc(createOutputImageWithCompletion:)
    open func createOutputImage(with completion: @escaping (_ outputImage: CGImage) -> Void)

    Parameters

    completion

    A completion handler that receives the newly created instance of CGImage once rendering is complete.

  • Applies all necessary filters and effects to the input image and converts it to a Data object containing the specified image file format and the given compressoin quality (if applicable).

    Declaration

    Swift

    @objc(generateOutputImageDataWithFormat:compressionQuality:metadataSourcePhoto:completionHandler:)
    open func generateOutputImageData(withFormat imageFormat: ImageFileFormat, compressionQuality: CGFloat, metadataSourcePhoto: Photo?, completionHandler: @escaping (_ outputImageData: Data?, _ imageWidth: CGFloat, _ imageHeight: CGFloat) -> Void)

    Parameters

    imageFormat

    The image file format to generate.

    compressionQuality

    The compression quality to apply. This will only be used for lossy image formats.

    metadataSourcePhoto

    The photo of which the metadata should be copied to the new image. If nil it uses the metadata of the original image, if available.

    completionHandler

    A completion handler that receives the newly created instance of Data once rendering is complete.

  • Draws the output image into the given EAGLContext.

    Declaration

    Swift

    @available(*, deprecated, renamed: "drawOutputImage(in:to:﹚")
    @discardableResult
    @objc(drawOutputImageInContext:toRect:viewportWidth:viewportHeight:)
    open func drawOutputImage(in context: EAGLContext, to rect: CGRect, viewportWidth: Int, viewportHeight: Int) -> CIImage

    Parameters

    context

    An instance of EAGLContext to draw into.

    rect

    The CGRect in which the output image should be drawn.

    viewportWidth

    The width of the view that displays the framebuffer’s content.

    viewportHeight

    The height of the view that displays the framebuffer’s content.

    Return Value

    The final rendered CIImage.

  • Draws the output image into the given EAGLContext.

    Declaration

    Swift

    @discardableResult
    @objc(drawOutputImageInContext:toRect:)
    open func drawOutputImage(in context: EAGLContext, to rect: CGRect) -> CIImage

    Parameters

    context

    An instance of EAGLContext to draw into.

    rect

    The CGRect in which the output image should be drawn. It is identical to the OpenGL viewport parameters of the framebuffer.

    Return Value

    The final rendered CIImage.

  • Draws the output image into the given EAGLContext.

    Declaration

    Swift

    open func drawOutputImage(in context: EAGLContext, to rect: CGRect, targetSize: CGSize? = nil, transform: CGAffineTransform = CGAffineTransform.identity, backgroundColor: UIColor? = nil, backgroundImage: CIImage? = nil, nearest: Bool = false, forceCropHack: Bool = false) -> CIImage

    Parameters

    context

    An instance of EAGLContext to draw into.

    rect

    The CGRect in which the output image should be drawn. It is identical to the OpenGL viewport parameters of the framebuffer.

    targetSize

    The target size of the image that should be rendered. It is used to scale the image appropriately. If this value is nil the size of the rect parameter is used instead.

    transform

    An optional affine transformation that should be applied to the image before rendering.

    backgroundColor

    An optional background color with infinite extents.

    backgroundImage

    An optional background image which will be cropped to the output image extents and it will be visible in transparent areas of the output image.

    nearest

    If true nearest-neighbor sampling is applied to the image before transform is applied. The default value is false.

    forceCropHack

    If true a workaround for a Core Image bug is enabled where the resulting image is cropped to a slightly smaller extent. Otherwise cropping is not applied and the result looks always as if clampedToExtent is enabled. The default value is false.

    Return Value

    The final rendered CIImage.

  • A class containing the created MTLCommandBuffer and the target CGColorSpace that were used to draw the image with a Metal context.

    See more

    Declaration

    Swift

    @objcMembers
    @objc(PESDKDrawReturnValue)
    open class DrawReturnValue : NSObject
  • Draws the output image into the given CAMetalDrawable.

    Declaration

    Swift

    @discardableResult
    open func drawOutputImage(for device: MTLDevice, in drawable: CAMetalDrawable, to rect: CGRect, commandQueue: MTLCommandQueue) -> DrawReturnValue?

    Parameters

    device

    The MTLDevice to use.

    drawable

    The drawable to draw into.

    rect

    The rectangle to draw into.

    commandQueue

    The MTLCommandQueue to use.

    Return Value

    A tuple containing the created MTLCommandBuffer and the target CGColorSpace that was used to render the image.

  • Draws the output image into the given CAMetalDrawable.

    Declaration

    Swift

    @discardableResult
    open func drawOutputImage(for device: MTLDevice, in drawable: CAMetalDrawable, to rect: CGRect, commandQueue: MTLCommandQueue, targetSize: CGSize? = nil, transform: CGAffineTransform = CGAffineTransform.identity, backgroundColor: UIColor? = nil, backgroundImage: CIImage? = nil, nearest: Bool = false, presentAndCommit: Bool = true, label: String? = nil) -> DrawReturnValue?

    Parameters

    device

    The MTLDevice to use.

    drawable

    The drawable to draw into.

    rect

    The rectangle to draw into.

    commandQueue

    The MTLCommandQueue to use.

    targetSize

    The target size of the image that should be rendered. It is used to scale the image appropriately. If this value is nil the size of the rect parameter is used instead.

    transform

    An optional affine transformation that should be applied to the image before rendering.

    backgroundColor

    An optional background color with infinite extents.

    backgroundImage

    An optional background image which will be cropped to the output image extents and it will be visible in transparent areas of the output image.

    nearest

    If true nearest-neighbor sampling is applied to the image before transform is applied. The default value is false.

    presentAndCommit

    If true the presentation is handled by this method otherwise the created MTLCommandBuffer is not committed and not scheduled for presentation. The default value is true.

    label

    An optional label to tag the created Metal resources.

    Return Value

    A tuple containing the created MTLCommandBuffer and the target CGColorSpace that was used to render the image.