use of org.eclipse.swt.graphics.ImageLoader in project yyl_example by Relucent.
the class ImageCanvasTest method main.
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
ImageViewer ic = new ImageViewer(shell);
shell.setLayout(new FillLayout());
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setText("Open an image file or cancel");
String string = dialog.open();
ImageLoader loader = new ImageLoader();
ImageData[] imageDatas = loader.load(string);
if (imageDatas.length == 0)
return;
else if (imageDatas.length == 1) {
ic.setImage(imageDatas[0]);
} else {
ic.setImages(imageDatas, loader.repeatCount);
}
ic.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
use of org.eclipse.swt.graphics.ImageLoader in project cubrid-manager by CUBRID.
the class BLOBCellPopupDialog method createImageCanvas.
/**
*
* Create the image canvas
*
*/
private void createImageCanvas() {
imageCanvas = new Composite(dataComposite, SWT.NONE);
imageCanvas.setLayoutData(new GridData(GridData.FILL_BOTH));
imageCanvas.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, -1));
imageCanvas.setLayout(new FillLayout());
InputStream in = null;
try {
if (currValue instanceof File) {
in = new FileInputStream((File) currValue);
} else if (currValue instanceof byte[]) {
in = new ByteArrayInputStream((byte[]) currValue);
}
if (in == null) {
imageCanvas.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
return;
}
ImageLoader loader = new ImageLoader();
ImageData[] imageDatas = loader.load(in);
if (imageDatas == null || imageDatas.length == 0) {
imageCanvas.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
return;
}
imageViewer = new ImageViewer(imageCanvas);
if (imageDatas.length == 1) {
imageViewer.setImage(imageDatas[0]);
} else {
imageViewer.setImages(imageDatas, loader.repeatCount);
}
imageViewer.pack();
} catch (Exception ex) {
imageCanvas.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
} finally {
Closer.close(in);
}
dataComposite.layout();
}
use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.
the class DesignExportToHTML method getHotspotString.
/**
* Code for generating a generic html hotspot with bounds, transitions, and
* potentially a background image and border.
*/
protected String getHotspotString(IWidget widget, String properties, String eventString) {
properties = properties.substring(0, properties.length() - 1);
ImageLoader imageLoader = new ImageLoader();
Image img = buildWidgetImage(widget);
if (img != null) {
imageLoader.data = new ImageData[] { img.getImageData() };
String imageName = getWidgetFileName(widget, ".jpg");
// create new FILE handler for the new imageSaver's use
File imageFile = new File(parentDir, imageName);
try {
imageLoader.save(imageFile.getCanonicalPath(), SWT.IMAGE_JPEG);
} catch (IOException ex) {
// We can continue even with exceptions on individual images
throw new ImageException("Failed saving image for HTML export", ex);
}
properties += " background-image: url(" + imageName + ");";
// dispose the image, it's not needed any more.
img.dispose();
}
return "<div " + properties + "\"" + eventString + ">" + widget.getTitle() + "</div>\n";
}
use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.
the class ClipboardUtil method fetchWindowsImageData.
protected static byte[] fetchWindowsImageData(ImageData imgData) {
// Set up an ImageLoader to convert the data to BMP
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { imgData };
// Save the ImageData to a byte stream
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(imgData.data.length);
loader.save(byteStream, SWT.IMAGE_BMP_RLE);
return byteStream.toByteArray();
}
use of org.eclipse.swt.graphics.ImageLoader in project cogtool by cogtool.
the class GraphicsUtil method cropImage.
/**
* Crops an image to the specified dimensions
* @param image the image to crop
* @param x the x-coordinate of the new origin
* @param y the y-coordinate of the new origin
* @param width the cropped width
* @param height the cropped height
* @return the cropped image
*/
public static byte[] cropImage(byte[] image, double x, double y, double width, double height) {
Image img = new Image(null, new ImageData(new ByteArrayInputStream(image)));
Image out = new Image(null, PrecisionUtilities.round(width), PrecisionUtilities.round(height));
GC gc = new GC(out);
gc.drawImage(img, -PrecisionUtilities.round(x), -PrecisionUtilities.round(y));
ImageLoader saver = new ImageLoader();
saver.data = new ImageData[] { out.getImageData() };
gc.dispose();
out.dispose();
img.dispose();
ByteArrayOutputStream ret = new ByteArrayOutputStream();
saver.save(ret, SWT.IMAGE_JPEG);
byte[] croppedImgData = ret.toByteArray();
try {
ret.close();
} catch (IOException e) {
// ignore
}
return croppedImgData;
}
Aggregations