Search in sources :

Example 6 with ImageLoader

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();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ImageData(org.eclipse.swt.graphics.ImageData) FillLayout(org.eclipse.swt.layout.FillLayout) ImageLoader(org.eclipse.swt.graphics.ImageLoader) FileDialog(org.eclipse.swt.widgets.FileDialog) Display(org.eclipse.swt.widgets.Display)

Example 7 with ImageLoader

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();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FillLayout(org.eclipse.swt.layout.FillLayout) FileInputStream(java.io.FileInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData) GridData(org.eclipse.swt.layout.GridData) ImageLoader(org.eclipse.swt.graphics.ImageLoader) File(java.io.File)

Example 8 with ImageLoader

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";
}
Also used : ImageException(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil.ImageException) IOException(java.io.IOException) ImageLoader(org.eclipse.swt.graphics.ImageLoader) Image(org.eclipse.swt.graphics.Image) File(java.io.File)

Example 9 with ImageLoader

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Example 10 with ImageLoader

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) ImageLoader(org.eclipse.swt.graphics.ImageLoader)

Aggregations

ImageLoader (org.eclipse.swt.graphics.ImageLoader)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Image (org.eclipse.swt.graphics.Image)7 ImageData (org.eclipse.swt.graphics.ImageData)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 File (java.io.File)4 InputStream (java.io.InputStream)3 GC (org.eclipse.swt.graphics.GC)3 ImageException (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil.ImageException)2 FileOutputStream (java.io.FileOutputStream)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1