SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

UI::HtmlDialog: no #write_image method #613

Open Fredosixx opened 3 years ago

Fredosixx commented 3 years ago

There used to be a write_image for UI::WebDialog.

This has not been reconducted in UI::HtmlDialog.

This is actually useful in case you wish to compose and generate custom images, for instance based on a HTML Canvas, among other cases.

REQUEST: If it is technically feasible, reintroduce a write_image method, same definition as for UI::WebDialog.

thomthom commented 3 years ago

Are there cases outside of images generated by Canvas?

Looking at the Canvas API it looks like it provides the bitmap data - which should be possible to pass to Ruby and into an ImageRep. https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Pixel_manipulation_with_canvas

If you are looking for the content of a canvas generated image then that would probably be preferable over grabbing an image of the whole window.

Fredosixx commented 3 years ago

Looking at the Canvas API it looks like it provides the bitmap data - which should be possible to pass to Ruby and into an ImageRep

I did not find a way to save canvas to a real image file, probably for security reason related to the browser. Getting the image raw data and then loading something as an ImageRep is something I can try (but it only works for SU2018 and above).

I think reconducting the same write_image method as UI::WebDialog would be simpler for all developers however.

thomthom commented 3 years ago

I can see the use case for both. 👍

DanRathbun commented 3 years ago

Yes I missed this old method in the new class as well.

Getting the image raw data and then loading something as an ImageRep is something I can try (but it only works for SU2018 and above).

Any change to the class would only work from that release forward and not be backward compatible anyway.

Fredosixx commented 3 years ago

Using Canvas and ImageRep works fine, but this is indeed a limitation (and a complication) versus a one-line call.