Interactive Ink

How can I drop in a picture?

Im hoping to be able to add images and potentially documents to the background and as interactable/ movable objects.

Thanks in advance.


1 person has this question

Dear Ethan,


it is currently possible to add images as objects using the addImage function.


Let us know if this helps!


Best regards,


Olivier

Hey Oliver. I'm having issues adding images as well....

The docs say it's expecting a NSString "File" "the image file to add.", what kind of string is expected?

I tried passing a base64 encoded NSData, the path to the image, even a URL to a static image online, and the UIImage itself.

I keep getting the following error

"Error, -[IINKEditor addImage:file:mimeType:error:]::390 addImage failed" UserInfo={NSLocalizedFailureReason=Error, -[IINKEditor addImage:file:mimeType:error:]::390 addImage failed}

Any hints?


Thanks!

Dear Gonzalo,


Normally, the "file" parameter should be the path of the image file. The image can be in GIF, JPEG or PNG.


You should also ensure you provide with the corresponding MIMETYPE.


Best regards,


Olivier


1 person likes this

Hi Olivier,

I'm having issues with it too. I'm getting this error: cannot add a new block into this block

I'm attempting to add it in aTtext Document where I've successfully been able to add other content blocks. My swift code is below.

editorViewController?.editor?.addImage(p, file: Bundle.main.resourcePath! + "/blueGradient.png", mimeType: IINKMimeType.PNG)}


Any Ideas? Thanks.

Hi Ethan.

I solved that issue by looping on the children bloks from the root block, getting the coordintes of the bottom block. On top of that, you have to add the blocks height and that'll give you a free position at the bottom of your document



 

NSArray* blocks = self.editorController.editor.rootBlock.children;
		
		CGFloat yPosition = 0;
		CGFloat blockYPosition = 0;
		
		for (IINKContentBlock* block in blocks) {
			blockYPosition = block.box.origin.y + block.box.size.height;
			if (yPosition < blockYPosition)
				yPosition = blockYPosition;
		}
		
		yPosition = yPosition + 5;

 

Hey Oliver. Saving the image to NSHomeDirectory() and passing that path fixed the issue.


Thanks!!

Dear Gonzalo,

Thank you for the update, I am glad it is working!

Best regards,

Olivier

Hey Oliver... I found a new issue, I'm not sure if it's a bug on the SDK or not, do tell me please.

I have a long Text Document

if I try to add an image as soon as I open the document, I get the following error:

Error Domain=Interactive Ink SDK Error Domain Code=1 "Error, -[IINKEditor addImage:file:mimeType:error:]::390 add block failed: could not create block at (x,y)" UserInfo={NSLocalizedFailureReason=Error, -[IINKEditor addImage:file:mimeType:error:]::390 add block failed: could not create block at (x,y)}


But if I scroll down to the bottom of the Text Document, and try to add the image then, the image is added.

I debugged, and in both cases the point I'm passing is (0,2573)

Thanks

PS: I just tried going back to the top of the document after successfully adding an image, and I get the same error trying again.

Dear Gonzalo,

this error is likely to occur for 2 reasons:

-Either a block that is not a Container Block already exists where you try to add the image

-Or the empty space around the position is too small

Applying the proper transform, as shown in the other topic is likely to help. Let me know if if is not the case.


Best regards,

Olivier


1 person likes this
Login or Signup to post a comment