eclipse.platform.swt icon indicating copy to clipboard operation
eclipse.platform.swt copied to clipboard

Introduce simple API to save ImageData to file and support '.jpg' extension

Open HannesWell opened this issue 8 months ago • 3 comments

Currently it's quite cumbersome to save ImageData into a file. screenshot from a Control or a Display. This proposes a convenience API to simplify this task.

This also complements the ImageData.load(Path) method introduced in

  • https://github.com/eclipse-platform/eclipse.platform.swt/pull/1767

It becomes also very simple to take and save a screenshot together with

  • https://github.com/eclipse-platform/eclipse.platform.swt/pull/2104, .

HannesWell avatar May 05 '25 22:05 HannesWell

Test Results

   545 files  + 6     545 suites  +6   29m 47s ⏱️ - 1m 1s  4 376 tests +37   4 358 ✅ +35   18 💤 +3  0 ❌  - 1  16 643 runs  +37  16 503 ✅ +35  140 💤 +3  0 ❌  - 1 

Results for commit b724b573. ± Comparison against base commit d1859ce5.

github-actions[bot] avatar May 05 '25 22:05 github-actions[bot]

Currently there are only convenience methods to load ImageData. Right now it's a constructor copying the first element of an ImageData-array into itself, but it will become just ImageData.load() with https://github.com/eclipse-platform/eclipse.platform.swt/pull/1767. Currently there is no (simple) way to save an Image(Data) to a file. So I think this closes a gap in the Image(Data) API and I don't consider this as cluttering the API. If we move this somewhere else then we can also just leave it as it, because many wont discover that way then anyways.

That one has to write an article about how to simply write an image to a file, is IMO an indication that the API is too complicated: https://www.eclipse.org/articles/Article-SWT-images/graphics-resources.html#Saving%20Images

Of course there are cases where one still needs an ImageLoader, but the simple cases should be simple.

HannesWell avatar May 06 '25 17:05 HannesWell

I don't think that adding methods to ImageData is a good idea, this should only be a data carrier and is not a general purpose place to put continence methods.

So why cant this static methods live in ImageLoader (or we can have a new ImageWriter)?

laeubi avatar May 07 '25 04:05 laeubi

Would you please split the *.jpg support in its own PR so it can be merged now?

akurtakov avatar Jun 09 '25 04:06 akurtakov