UIImage into PTImage

I’m using custom annotations with different images, but one of them is dynamically created based on the user so it’s not stored in the assets.
I would like to how to turn a UIImage into a PTImage.
The only way I was able to make it work was by saving the image locally to pass the image path to +Create:filename: function. I’ve also tried using the image data with this function CreateWithData:buf:buf_size:width:height:bpc:color_space:encoder_hints:, but had so success.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


Hi Rafael,

You can use PTImage’s CreateWithDataSimple API.

Here’s an example for you, that might be helpful.

NSData* imageData = UIImagePNGRepresentation(image);
PTObjSet* hintSet = [[PTObjSet alloc] init];
PTObj* encoderHints = [hintSet CreateArray];
[encoderHints PushBackName:@"JPEG"];
PTImage* stampImage = [PTImage CreateWithDataSimple:[doc GetSDFDoc] buf:imageData buf_size:imageData.length encoder_hints:encoderHints];

Let us know if it works for you.

Best Regards,

Thank you for you reply.
This is how I used it based on your reply and it worked.

private extension UIImage {
    func getPTImage(doc: PTPDFDoc) -> PTImage? {
        let imageData = self.pngData()
        let hintSet = PTObjSet()!
        let encoderHints = hintSet.createArray()
        let ptImage = PTImage.create(withDataSimple: doc.getSDFDoc(),
                                   buf: imageData,
                                   buf_size: UInt(imageData?.count ?? 0),
                                   encoder_hints: encoderHints)
        return ptImage

Thank you for letting us know. Glad to know it is working for you.

Please let us know if you have any other questions or comments.

Best Regards,