iink SDK on Device

Answered

PNG export, image size, iOS

 I have some problems with exporting image from IINKEditor (using ImageDrawer from reference implementation). My code looks like this:

 
let imageParams:IINKParameterSet = self.editor.engine.createParameterSet()!

try imageParams.setNumber(0, forKey:"export.image.viewport.x")
try imageParams.setNumber(0, forKey:"export.image.viewport.y")
try imageParams.setNumber(self.editor.viewSize.width, forKey:"export.image.viewport.width")
try imageParams.setNumber(self.editor.viewSize.height, forKey:"export.image.viewport.height")

self.editor.waitForIdle()
let loader = ImageLoader()
let drawer = ImageDrawer(imageLoader: loader)
drawer.backgroundColor = .white
try self.editor.export_(self.editor.rootBlock, toFile: fullPath, mimeType: .PNG, imageDrawer: drawer, overrideConfiguration: imageParams)

 (self.editor is IINKEditor that handles all the drawing)

I want to get image in the exact dimensions as it is on screen. So that if I put the resulting image exactly over my view, it will look exactly the same. There is no scrolling or scaling involved, self.editor.viewSize is exactly the same as in real view.


1) But the exported image I get has twice the width and height of viewSize, AND consist only of upper left quarter of the real view. So it is like quarter of the view made 4 times larger in both dimensions. There is clearly some scaling or transformations involved, but I don't know where.

2) PNG always has transparent background, even though I set drawer.backgroundColor. If I export to JPEG, it always has white background, even though I set drawer.backgroundColor to something else.


Best Answer

Hello,


Thank you for your update.


The iink editor works on a model with physical coordinates in mm, and performs back and forth transforms from view to physical coordinates. 

This is where both the device and image resolutions come into play.


We have not reproduced your issue.

So, could you please, isolate the code where you perform your export and test within one of the sample (Demo or GetStarted) and then share it with us?

Sharing with us an iink sample with the correspond JIIX export, both image exports (with default and customised image export tuning) , as well as the captured screen would also be helpful.


Regards,


Gwenaëlle




Dear Kozarek,


Thank you for your question.


Could you please, also share the content part type that you are using?


Regards,


Gwenaëlle



It's "Drawing" type. No converted text, just pencil lines.

I have done some more tests. If I specify configuration like this:

 

try imageParams.setNumber(0, forKey:"export.image.viewport.x")
try imageParams.setNumber(0, forKey:"export.image.viewport.y")
try imageParams.setNumber(2.27 * Double(self.editor.viewSize.width), forKey:"export.image.viewport.width")
try imageParams.setNumber(2.27 * Double(self.editor.viewSize.height), forKey:"export.image.viewport.height")
try imageParams.setNumber(4096, forKey:"export.image-max-size")

 ... then the resulting image captures almost exactly the whole correct area of view. But both dimensions of resulting image are 4.54 times bigger then those of self.editor.viewSize . That is by the way over 5000px width, which seems to violate export.image-max-size. Even if I specifically set it to 4096, as I show above.

To me, the biggest problems are the image and viewport dimensions. I could live with multiplying sizes by 2.27 and then reducing image size by 4.45, but I have no idea where these constants came from and if they can be relied upon. Violation of image-max-size does not bother me much, but it looks clearly like a bug to me.

 

Thank your for your update.


You should probably tune the image resolution as well, with the "export.export.image-resolution" configuration parameter, as
by default the resolution of the exported image is 300 dpi.



So imagine your image resolution is 200 dpi,  your code would probably be something like:


let imageParams:IINKParameterSet = self.editor.engine.createParameterSet()!

try imageParams.setNumber(0, forKey:"export.image.viewport.x")
try imageParams.setNumber(0, forKey:"export.image.viewport.y")
try imageParams.setNumber(self.editor.viewSize.width, forKey:"export.image.viewport.width")
try imageParams.setNumber(self.editor.viewSize.height, forKey:"export.image.viewport.height")
try imageParams.setNumber(200, forKey:"export.image-resolution")

self.editor.waitForIdle()
let loader = ImageLoader()
let drawer = ImageDrawer(imageLoader: loader)
drawer.backgroundColor = .white
try self.editor.export_(self.editor.rootBlock, toFile: fullPath, mimeType: .PNG, imageDrawer: drawer, overrideConfiguration: imageParams)




Best regards,


Gwenaëlle



I tried the resolution just now, it does not make any difference. Exported image size is always the same, even with resolution 10. BTW I probably don't understand what resolution is that configuration item about. I mean, resolution makes sense when converting between real-world units and pixels. But if I set viewport in pixels and image-max-size in pixels, how could it be influenced by resolution?

Answer

Hello,


Thank you for your update.


The iink editor works on a model with physical coordinates in mm, and performs back and forth transforms from view to physical coordinates. 

This is where both the device and image resolutions come into play.


We have not reproduced your issue.

So, could you please, isolate the code where you perform your export and test within one of the sample (Demo or GetStarted) and then share it with us?

Sharing with us an iink sample with the correspond JIIX export, both image exports (with default and customised image export tuning) , as well as the captured screen would also be helpful.


Regards,


Gwenaëlle