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;
}
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;
}
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;
}
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;
}
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");
}
Aggregations