diff --git a/news/4.39/platform_isv.md b/news/4.39/platform_isv.md index 96cc806d..94768328 100644 --- a/news/4.39/platform_isv.md +++ b/news/4.39/platform_isv.md @@ -67,3 +67,50 @@ pdf.dispose(); This enhancement eliminates the need for external PDF libraries and provides a native, platform-integrated solution for PDF generation in SWT applications. See [Snippet388](https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet388.java) for a complete working example. + +### ImageDataAtSizeProvider Referencable + +
+Contributors + +- [Michael Bangas](https://github.com/Michael5601) +- [Arun Jose](https://github.com/arunjose696) +- [Heiko Klare](https://github.com/HeikoKlare) +
+ +The `ImageDataAtSizeProvider` interface is now available as public API. +It allows SWT users to provide image data at a custom width and height, rather than relying solely on zoom-based scaling. +To this end, the `getImageData(int width, int height)` method of the provider needs to be implemented. + +The `ImageDataAtSizeProvider` is particularly useful in cases where precise control over image dimensions is needed, allowing users to create image data at a specific width and height. + +If such a provider shall also be used to retrieve image data for specific zooms, the `getDefaultSize() : Point` method can overwritten to define the size that the image data shall have at 100% zoom. +In that case, calls to `getImageData(int zoom)` are delegated to `getImageData(int width, int height)` with the given zoom applied to the default size. + +#### Example Usage + +```java +// Lambda implementation of ImageDataAtSizeProvider +ImageDataAtSizeProvider provider = (width, height) -> { + PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF); + ImageData data = new ImageData(width, height, 32, palette); + int pixel = palette.getPixel(drawnRgb); + + // Draw a border + for (int i = 0; i < width; i++) { + data.setPixel(i, 0, pixel); + data.setPixel(i, height - 1, pixel); + } + for (int i = 0; i < height; i++) { + data.setPixel(0, i, pixel); + data.setPixel(width - 1, i, pixel); + } + return data; +}; + +// Create an Image using the provider +Image image = new Image(display, provider); +``` + +Images from this provider can be drawn at a specific size using `GC.drawImage(Image, int, int, int, int)`. +See also the [news on the introduction of that method](../4.38/platform_isv.md#new-gc-api-for-drawing-scaled-images). \ No newline at end of file