Community
Participate
Working Groups
I tried to save JPEG with ImageData 24 bit depth, height 240 pixels, width 1 pixel and it thrown this exception: org.eclipse.swt.SWTException: i/o error (java.lang.ArrayIndexOutOfBoundsException: -1) at org.eclipse.swt.SWT.error(SWT.java:2691) at org.eclipse.swt.SWT.error(SWT.java:2616) at org.eclipse.swt.internal.image.FileFormat.unloadIntoStream(FileFormat.java:111) at org.eclipse.swt.internal.image.FileFormat.save(FileFormat.java:99) at org.eclipse.swt.graphics.ImageLoader.save(ImageLoader.java:194)
Can you please attach the image to this bug report? Thanks!
It is not dependent on particular image, so I've created test snippet instead. And I've found that on Windows it doesn't work too. import java.io.*; import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; public class Main { public static void main(String[] args) { final Shell shell = new Shell(SWT.SHELL_TRIM); shell.setLayout(new GridLayout(5, true)); new Label(shell, SWT.NONE).setText("Width"); final Text width = new Text(shell, SWT.BORDER); width.setText("1"); width.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); new Label(shell, SWT.NONE).setText("Height"); final Text height = new Text(shell, SWT.BORDER); height.setText("240"); height.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); Button b = new Button(shell, SWT.NONE); b.setText("Test"); shell.setDefaultButton(b); final Display d = shell.getDisplay(); b.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int w; int h; try { w = Integer.parseInt(width.getText().trim()); h = Integer.parseInt(height.getText().trim()); } catch (NumberFormatException exc) { exc.printStackTrace(); e.doit = false; return; } Image i = new Image(d, w, h); i.setBackground(d.getSystemColor(SWT.COLOR_RED)); ImageLoader il = new ImageLoader(); il.data = new ImageData[] {i.getImageData()}; try { il.save(new ByteArrayOutputStream(), SWT.IMAGE_JPEG); } catch (Exception exc) { exc.printStackTrace(); MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR); mb.setMessage("error"); mb.open(); } } }); shell.pack(true); shell.open(); while (!shell.isDisposed()) { if (!d.readAndDispatch()) { d.sleep(); } } } }
I posted a fix for bug 47783 that also fixes this bug. I tested it with the test case posted here to confirm.
Fixed > 20080121. Released the patch from bug 47783 verbatim. Tested it with the snippet in comment 2, and the snippet in bug 47783. Also created a bunch of width 1 images and tested against those. Walked through the code, and I am happy that the supplied patch exactly fixes these 2 bugs. Thanks again, Mark!