Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,56 @@ public Image(Device device, int width, int height) {
}
}

/**
* Constructs an empty instance of this class with the width
* (the x coordinate) and height (the y coordinate) of the
* specified point. The result may be drawn upon by creating
* a GC and using any of its drawing operations, as shown in
* the following example:
* <pre>
* Image i = new Image(device, boundsRectangle);
* GC gc = new GC(i);
* gc.drawRectangle(0, 0, 50, 50);
* gc.dispose();
* </pre>
* <p>
* Note: Some platforms may have a limitation on the size
* of image that can be created (size depends on width, height,
* and depth). For example, Windows 95, 98, and ME do not allow
* images larger than 16M.
* </p>
* <p>
* You must dispose the image when it is no longer required.
* </p>
*
* @param device the device on which to create the image
* @param size a point specifying the image's width and height (must not be null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* <li>ERROR_NULL_ARGUMENT - if the bounds point is null</li>
* <li>ERROR_INVALID_ARGUMENT - if either the points width or height is negative</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
* </ul>
*
* @see #dispose()
* @since 3.133
*/
public Image(Device device, Point size) {
super(device);
if (size == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
NSAutoreleasePool pool = null;
if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
init(size.x, size.y);
init();
} finally {
if (pool != null) pool.release();
}
}

/**
* Constructs a new instance of this class based on the
* provided image, with an appearance that varies depending
Expand Down Expand Up @@ -529,7 +579,7 @@ private void createRepFromSourceAndApplyFlag(NSBitmapImageRep srcRep, int srcWid
*
* @see #dispose()
*
* @deprecated use {@link Image#Image(Device, int, int)} instead
* @deprecated use {@link Image#Image(Device, int, int)} or {@link Image#Image(Device, Point)} instead
*/
@Deprecated(since = "2025-06", forRemoval = true)
public Image(Device device, Rectangle bounds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,49 @@ public final class Image extends Resource implements Drawable {
* @see #dispose()
*/
public Image(Device device, int width, int height) {
this(device, new Point(width, height));
}

/**
* Constructs an empty instance of this class with the width
* (the x coordinate) and height (the y coordinate) of the
* specified point. The result may be drawn upon by creating
* a GC and using any of its drawing operations, as shown in
* the following example:
* <pre>
* Image i = new Image(device, boundsRectangle);
* GC gc = new GC(i);
* gc.drawRectangle(0, 0, 50, 50);
* gc.dispose();
* </pre>
* <p>
* Note: Some platforms may have a limitation on the size
* of image that can be created (size depends on width, height,
* and depth). For example, Windows 95, 98, and ME do not allow
* images larger than 16M.
* </p>
* <p>
* You must dispose the image when it is no longer required.
* </p>
*
* @param device the device on which to create the image
* @param size a point specifying the image's width and height (must not be null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* <li>ERROR_NULL_ARGUMENT - if the bounds point is null</li>
* <li>ERROR_INVALID_ARGUMENT - if either the points width or height is negative</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
* </ul>
*
* @see #dispose()
* @since 3.133
*/
public Image(Device device, Point size) {
super(device);
Point size = new Point(width, height);
if (size == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
init(size.x, size.y);
init();
}
Expand Down Expand Up @@ -406,7 +447,7 @@ public Image(Device device, Image srcImage, int flag) {
*
* @see #dispose()
*
* @deprecated use {@link Image#Image(Device, int, int)} instead
* @deprecated use {@link Image#Image(Device, int, int)} or {@link Image#Image(Device, Point)} instead
*/
@Deprecated(since = "2025-06", forRemoval = true)
public Image(Device device, Rectangle bounds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,51 @@ public Image(Device device, int width, int height) {
this.device.registerResourceWithZoomSupport(this);
}

/**
* Constructs an empty instance of this class with the width
* (the x coordinate) and height (the y coordinate) of the
* specified point. The result may be drawn upon by creating
* a GC and using any of its drawing operations, as shown in
* the following example:
* <pre>
* Image i = new Image(device, boundsRectangle);
* GC gc = new GC(i);
* gc.drawRectangle(0, 0, 50, 50);
* gc.dispose();
* </pre>
* <p>
* Note: Some platforms may have a limitation on the size
* of image that can be created (size depends on width, height,
* and depth). For example, Windows 95, 98, and ME do not allow
* images larger than 16M.
* </p>
* <p>
* You must dispose the image when it is no longer required.
* </p>
*
* @param device the device on which to create the image
* @param size a point specifying the image's width and height (must not be null)
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* <li>ERROR_NULL_ARGUMENT - if the bounds point is null</li>
* <li>ERROR_INVALID_ARGUMENT - if either the points width or height is negative</li>
* </ul>
* @exception SWTError <ul>
* <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li>
* </ul>
*
* @see #dispose()
* @since 3.133
*/
public Image(Device device, Point size) {
super(device);
if (size == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
this.imageProvider = new PlainImageProviderWrapper(size.x, size.y);
init();
this.device.registerResourceWithZoomSupport(this);
}

/**
* Constructs a new instance of this class based on the
* provided image, with an appearance that varies depending
Expand Down Expand Up @@ -393,7 +438,7 @@ public Image(Device device, Image srcImage, int flag) {
*
* @see #dispose()
*
* @deprecated use {@link Image#Image(Device, int, int)} instead
* @deprecated use {@link Image#Image(Device, int, int)} or {@link Image#Image(Device, Point)} instead
*/
@Deprecated(since = "2025-06", forRemoval = true)
public Image(Device device, Rectangle bounds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public static void main(String[] args) {
label.setImage(null);
image.dispose ();
}
Rectangle rect = group.getBounds();
image = new Image (display, rect.width, rect.height);
image = new Image (display, group.getSize());
GC gc = new GC (image);
boolean success = group.print (gc);
gc.dispose ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public static void main(String[] args) {
button.addListener(SWT.Selection, event -> {
Point tableSize = table.getSize();
GC gc = new GC(table);
final Image image =
new Image(display, tableSize.x, tableSize.y);
final Image image = new Image(display, tableSize);
gc.copyArea(image, 0, 0);
gc.dispose();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main (String [] args) {
Image originalImage = toolBar.getBackgroundImage();

Point p = toolBar.getSize();
Image bg = new Image(display, p.x, p.y);
Image bg = new Image(display, p);

GC gc = new GC(bg);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void main(String[] args) {
shell.setSize(cSize);

shell.open();
Image canvas = new Image(display, cSize.x, cSize.y);
Image canvas = new Image(display, cSize);
GC gc = new GC(canvas);
composite.print(gc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ private static Composite canvas(Display display, Shell shell) {
}

private static void snapshot(Display display, Composite composite, String filename) {
Rectangle bounds = composite.getBounds();
Image image = new Image(display, bounds.width, bounds.height);
Image image = new Image(display, composite.getSize());
GC gc = new GC(image);
composite.print(gc);
gc.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ private static Composite canvas(Display display, Shell shell) {
}

private static void snapshot(Display display, Composite composite, String filename) {
Rectangle bounds = composite.getBounds();
Image image = new Image(display, bounds.width, bounds.height);
Image image = new Image(display, composite.getSize());
GC gc = new GC(image);
composite.print(gc);
gc.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
Expand Down Expand Up @@ -69,8 +68,7 @@ public static void main(String[] args) {
}

private static void saveImage(Control control, String filename, int format) {
Rectangle bounds = control.getBounds();
Image image = new Image(control.getDisplay(), bounds.width, bounds.height);
Image image = new Image(control.getDisplay(), control.getSize());
GC gc = new GC(image);
control.print(gc);
gc.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
Expand Down Expand Up @@ -61,8 +60,7 @@ public static void main(String[] args) {
}

private static void saveImage(Shell shell, String filename, int format) {
Rectangle bounds = shell.getBounds();
Image image = new Image(shell.getDisplay(), bounds.width, bounds.height);
Image image = new Image(shell.getDisplay(), shell.getSize());
// Printing the client area will result in a warning and only the client area being printed
// Image image = new Image(shell.getDisplay(), shell.getClientArea());
GC gc = new GC(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,34 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
image.dispose();
}

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_Point() {
Image image;
IllegalArgumentException e;

e = assertThrows(IllegalArgumentException.class, () -> new Image(display, new Point(-1, 10)));
assertSWTProblem("Incorrect exception thrown for width < 0", SWT.ERROR_INVALID_ARGUMENT, e);

e = assertThrows(IllegalArgumentException.class, () -> new Image(display, new Point(0, 10)));
assertSWTProblem("Incorrect exception thrown for width == 0", SWT.ERROR_INVALID_ARGUMENT, e);

e = assertThrows(IllegalArgumentException.class, () -> new Image(display, new Point(10, -1)));
assertSWTProblem("Incorrect exception thrown for height < 0", SWT.ERROR_INVALID_ARGUMENT, e);

e = assertThrows(IllegalArgumentException.class, () -> new Image(display, new Point(10, 0)));
assertSWTProblem("Incorrect exception thrown for height == 0", SWT.ERROR_INVALID_ARGUMENT, e);

e = assertThrows(IllegalArgumentException.class, () -> new Image(display, (Point) null));
assertSWTProblem("Incorrect exception thrown for size == null", SWT.ERROR_NULL_ARGUMENT, e);

// valid images
image = new Image(null, new Point(10, 10));
image.dispose();

image = new Image(display, new Point(10, 10));
image.dispose();
}

@Test
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_ImageData() {
IllegalArgumentException e;
Expand Down
Loading