Search in sources :

Example 21 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cubrid-manager by CUBRID.

the class ImageViewer method createImageByImageData.

/**
	 * 
	 * Create the image by image data
	 * 
	 */
private void createImageByImageData() {
    images = new Image[imageDatas.length];
    //Get the image size
    int width = imageDatas[0].width;
    int height = imageDatas[0].height;
    //Create every image
    int disposalMethod = SWT.DM_FILL_BACKGROUND;
    for (int i = 0; i < imageDatas.length; i++) {
        ImageData currImageData = imageDatas[i];
        images[i] = new Image(display, width, height);
        GC currImageGC = new GC(images[i]);
        switch(disposalMethod) {
            case SWT.DM_FILL_PREVIOUS:
                //Draw the second last image. 
                currImageGC.drawImage(images[i - 2], 0, 0);
                break;
            case SWT.DM_FILL_NONE:
            case SWT.DM_UNSPECIFIED:
                //Draw the last image. 
                currImageGC.drawImage(images[i - 1], 0, 0);
                break;
            default:
                //If DM_FILL_BACKGROUND or anything else, fill with default background
                currImageGC.setBackground(background);
                currImageGC.fillRectangle(0, 0, width, height);
                break;
        }
        //Draw the current image,then clean up
        Image currImage = new Image(display, currImageData);
        currImageGC.drawImage(currImage, 0, 0, currImageData.width, currImageData.height, currImageData.x, currImageData.y, currImageData.width, currImageData.height);
        currImage.dispose();
        currImageGC.dispose();
        //Compute the next disposal method.
        disposalMethod = currImageData.disposalMethod;
        if (i == 0 && disposalMethod == SWT.DM_FILL_PREVIOUS) {
            disposalMethod = SWT.DM_FILL_NONE;
        }
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 22 with ImageData

use of org.eclipse.swt.graphics.ImageData in project MonjaDB by Kanatoko.

the class SWTResourceManager method getImage.

/**
	 * Returns an {@link Image} encoded by the specified {@link InputStream}.
	 * 
	 * @param stream
	 *            the {@link InputStream} encoding the image data
	 * @return the {@link Image} encoded by the specified input stream
	 */
protected static Image getImage(InputStream stream) throws IOException {
    try {
        Display display = Display.getCurrent();
        ImageData data = new ImageData(stream);
        if (data.transparentPixel > 0) {
            return new Image(display, data, data.getTransparencyMask());
        }
        return new Image(display, data);
    } finally {
        stream.close();
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Image(org.eclipse.swt.graphics.Image) Display(org.eclipse.swt.widgets.Display)

Example 23 with ImageData

use of org.eclipse.swt.graphics.ImageData in project dbeaver by serge-rider.

the class DBeaverIcons method getViewMenuImage.

public static synchronized Image getViewMenuImage() {
    if (viewMenuImage == null) {
        Display d = Display.getCurrent();
        Image viewMenu = new Image(d, 16, 16);
        Image viewMenuMask = new Image(d, 16, 16);
        Display display = Display.getCurrent();
        GC gc = new GC(viewMenu);
        GC maskgc = new GC(viewMenuMask);
        gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
        gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        int[] shapeArray = new int[] { 6, 3, 15, 3, 11, 7, 10, 7 };
        gc.fillPolygon(shapeArray);
        gc.drawPolygon(shapeArray);
        Color black = display.getSystemColor(SWT.COLOR_BLACK);
        Color white = display.getSystemColor(SWT.COLOR_WHITE);
        maskgc.setBackground(black);
        maskgc.fillRectangle(0, 0, 16, 16);
        maskgc.setBackground(white);
        maskgc.setForeground(white);
        maskgc.fillPolygon(shapeArray);
        maskgc.drawPolygon(shapeArray);
        gc.dispose();
        maskgc.dispose();
        ImageData data = viewMenu.getImageData();
        data.transparentPixel = data.getPixel(0, 0);
        viewMenuImage = new Image(d, viewMenu.getImageData(), viewMenuMask.getImageData());
        viewMenu.dispose();
        viewMenuMask.dispose();
    }
    return viewMenuImage;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) DBPImage(org.jkiss.dbeaver.model.DBPImage) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 24 with ImageData

use of org.eclipse.swt.graphics.ImageData in project dbeaver by serge-rider.

the class OverlayImageDescriptor method drawTopLeft.

protected void drawTopLeft(ImageDescriptor[] overlays) {
    if (overlays == null)
        return;
    int length = overlays.length;
    int x = 0;
    for (int i = 0; i < 3; i++) {
        if (i < length && overlays[i] != null) {
            ImageData id = overlays[i].getImageData();
            drawImage(id, x, 0);
            x += id.width;
        }
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Point(org.eclipse.swt.graphics.Point)

Example 25 with ImageData

use of org.eclipse.swt.graphics.ImageData in project dbeaver by serge-rider.

the class OverlayImageDescriptor method drawBottomRight.

protected void drawBottomRight(ImageDescriptor[] overlays) {
    if (overlays == null)
        return;
    int length = overlays.length;
    int x = getSize().x;
    for (int i = 2; i >= 0; i--) {
        if (i < length && overlays[i] != null) {
            ImageData id = overlays[i].getImageData();
            x -= id.width;
            drawImage(id, x, getSize().y - id.height);
        }
    }
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Point(org.eclipse.swt.graphics.Point)

Aggregations

ImageData (org.eclipse.swt.graphics.ImageData)132 Image (org.eclipse.swt.graphics.Image)78 PaletteData (org.eclipse.swt.graphics.PaletteData)38 RGB (org.eclipse.swt.graphics.RGB)33 Point (org.eclipse.swt.graphics.Point)32 Test (org.junit.Test)26 InputStream (java.io.InputStream)24 GC (org.eclipse.swt.graphics.GC)19 IOException (java.io.IOException)18 SWTException (org.eclipse.swt.SWTException)14 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)13 Rectangle (org.eclipse.swt.graphics.Rectangle)12 Color (org.eclipse.swt.graphics.Color)11 ImageLoader (org.eclipse.swt.graphics.ImageLoader)11 Display (org.eclipse.swt.widgets.Display)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Cursor (org.eclipse.swt.graphics.Cursor)7 Composite (org.eclipse.swt.widgets.Composite)7 GradientPaint (java.awt.GradientPaint)5 URL (java.net.URL)5