Search in sources :

Example 71 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class WindowUtil method getClosedHandCursor.

public static Cursor getClosedHandCursor() {
    if (CLOSED_HAND_CURSOR == null) {
        ImageData curData = GraphicsUtil.getImageDataFromResource("edu/cmu/cs/hcii/cogtool/resources/closed_hand.gif");
        if (curData == null) {
            return null;
        }
        CLOSED_HAND_CURSOR = new Cursor(GLOBAL_DISPLAY, curData, 8, 8);
    }
    return CLOSED_HAND_CURSOR;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Cursor(org.eclipse.swt.graphics.Cursor)

Example 72 with ImageData

use of org.eclipse.swt.graphics.ImageData 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)

Example 73 with ImageData

use of org.eclipse.swt.graphics.ImageData in project translationstudio8 by heartsome.

the class BrowserViewPart method getTitleImage.

public Image getTitleImage(String iamgeUrl) {
    Image cacheImage = titleIamgeCache.get(iamgeUrl);
    if (null != cacheImage) {
        return cacheImage;
    }
    URL url = null;
    try {
        url = new URL(iamgeUrl);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    if (null == url) {
        return null;
    }
    Image image = null;
    try {
        ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
        ImageData imageData = imageDescriptor.getImageData();
        ImageData scaledTo = imageData.scaledTo(16, 16);
        image = ImageDescriptor.createFromImageData(scaledTo).createImage();
    } catch (Exception e) {
        // no need handle
        return null;
    }
    if (null != image) {
        titleIamgeCache.put(iamgeUrl, image);
    }
    return image;
}
Also used : MalformedURLException(java.net.MalformedURLException) ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Example 74 with ImageData

use of org.eclipse.swt.graphics.ImageData in project translationstudio8 by heartsome.

the class LanguageLabelProvider method getImage.

public Image getImage(Object element) {
    if (element instanceof Language) {
        Language lang = (Language) element;
        String code = lang.getCode();
        String imagePath = lang.getImagePath();
        if (imagePath != null && !imagePath.equals("")) {
            ImageDescriptor imageDesc = Activator.getImageDescriptor(imagePath);
            if (imageDesc != null) {
                ImageData data = imageDesc.getImageData().scaledTo(16, 12);
                Image image = new Image(Display.getDefault(), data);
                // 销毁原来的图片
                Image im = imageCache.put(code, image);
                if (im != null && !im.isDisposed()) {
                    im.dispose();
                }
                return image;
            }
        }
    }
    return null;
}
Also used : Language(net.heartsome.cat.common.locale.Language) ImageData(org.eclipse.swt.graphics.ImageData) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image)

Example 75 with ImageData

use of org.eclipse.swt.graphics.ImageData in project cogtool by cogtool.

the class HCIPACmd method buildActionStepInsert.

protected static void buildActionStepInsert(AUndertaking task, AScriptStep step, Demonstration demo, StringBuilder php) {
    int hcipaStep = task.getTaskGroup().getUndertakings().indexOf(task) + 1;
    Frame curFrame = step.getCurrentFrame();
    TransitionSource src = step.getStepFocus();
    String labelAction;
    if (src == null) {
        labelAction = "None";
    } else {
        labelAction = quotePHP(quoteSQL(src.getLabel()));
    }
    int order = demo.getSteps().indexOf(step) + 1;
    byte[] bkgImage = curFrame.getBackgroundImage();
    if (bkgImage != null) {
        ImageData imgData = new ImageData(new ByteArrayInputStream(bkgImage));
        bkgImage = GraphicsUtil.convertImageType(imgData, SWT.IMAGE_JPEG);
        int imgSize = bkgImage.length;
        String imgName = (String) curFrame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
        php.append("\t$imgType = \"'image/jpeg'\";\n\t");
        php.append("$imgLength = " + imgSize + ";\n\t");
        php.append("$bkgImage = '0x' . bin2hex(base64_decode(str_replace(array('.', '_', '-'), array('+', '/', '='), \"");
        php.append(Base64.encode(bkgImage));
        php.append("\")));\n\n\t");
        if ((imgName == null) || NullSafe.equals(WidgetAttributes.NO_IMAGE, imgName)) {
            php.append("$imgName = 'null';\n\t");
        } else {
            php.append("$imgName = \"'\" . mysql_real_escape_string(basename(\n<<<SQL__INSERT__STRING\n");
            php.append(imgName);
            php.append("\nSQL__INSERT__STRING\n)) . \"'\";\n\n\t");
        }
    } else {
        php.append("\t$imgType = 'null';\n\t");
        php.append("$imgLength = 'null';\n\t");
        php.append("$bkgImage = 'null';\n\t");
        php.append("$imgName = 'null';\n\n\t");
    }
    php.append("Add_Task_Action($deviceId,\n\t");
    php.append(hcipaStep + ",\n\t" + order + ",\n\t");
    php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
    php.append("\"" + quotePHP(quoteSQL(curFrame.getName())) + "\",\n\t");
    php.append("\"" + labelAction + "\");\n\n");
//        php.append("$sqlStmt =\n<<<SQL__INSERT__STRING\n\t");
//        php.append(SQL_INSERT + "HCIPA_Actions (hcipa_id,\n\thcipa_step,\n\t");
//        php.append("hcipa_order,\n\tImage,\n\tImage_Name,\n\tImage_Size,\n\tImage_Type,\n\t");
//        php.append("Next_User_Action,\n\tLabel_User_Action)\n\t");
//        php.append(SQL_VALUES + " ($deviceId,\n\t" + hcipaStep + ",\n\t" + order + ",\n\t");
//        php.append("$bkgImage,\n\t$imgName,\n\t$imgLength,\n\t$imgType,\n\t");
//        php.append("'" + quoteSQL(curFrame.getName()) + "',\n\t'" + labelAction + "'");
//        php.append(")\n");
//        php.append("SQL__INSERT__STRING\n;\n\n\t");
//        php.append("mysql_query($sqlStmt);\n\n");
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData)

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