Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HannesWell
Copy link
Member

@HannesWell HannesWell commented May 5, 2025

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

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

Copy link
Contributor

github-actions bot commented May 5, 2025

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 b724b57. ± Comparison against base commit d1859ce.

@HannesWell HannesWell force-pushed the add-ImageData-save branch from 3627584 to 19b2b72 Compare May 5, 2025 23:24
@HannesWell HannesWell changed the title Introduce simple API to save ImageData to a file and support .jpg Introduce simple API to save ImageData to file and support jpg extension May 5, 2025
@HannesWell HannesWell changed the title Introduce simple API to save ImageData to file and support jpg extension Introduce simple API to save ImageData to file and support '.jpg' extension May 5, 2025
Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should clutter the ImageData class more can't we use ImageLoader(sic) for this that already is used internally anyways?

@HannesWell
Copy link
Member Author

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 #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.

@laeubi
Copy link
Contributor

laeubi commented May 7, 2025

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)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants