本文整理匯總了Java中org.eclipse.swt.graphics.Image.getImageData方法的典型用法代碼示例。如果您正苦於以下問題:Java Image.getImageData方法的具體用法?Java Image.getImageData怎麽用?Java Image.getImageData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.swt.graphics.Image
的用法示例。
在下文中一共展示了Image.getImageData方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveEditorContentsAsImage
import org.eclipse.swt.graphics.Image; //導入方法依賴的package包/類
private static void saveEditorContentsAsImage(IEditorPart editorPart, GraphicalViewer viewer, String saveFilePath, int format) {
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getEditPartRegistry().get(LayerManager.ID);
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);// rootEditPart.getFigure();
Rectangle rootFigureBounds = rootFigure.getBounds();
Control figureCanvas = viewer.getControl();
GC figureCanvasGC = new GC(figureCanvas);
Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height);
GC imageGC = new GC(img);
imageGC.setBackground(figureCanvasGC.getBackground());
imageGC.setForeground(figureCanvasGC.getForeground());
imageGC.setFont(figureCanvasGC.getFont());
imageGC.setLineStyle(figureCanvasGC.getLineStyle());
imageGC.setLineWidth(figureCanvasGC.getLineWidth());
imageGC.setXORMode(figureCanvasGC.getXORMode());
Graphics imgGraphics = new SWTGraphics(imageGC);
rootFigure.paint(imgGraphics);
ImageData[] imgData = new ImageData[1];
imgData[0] = img.getImageData();
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = imgData;
imgLoader.save(saveFilePath, format);
figureCanvasGC.dispose();
imageGC.dispose();
img.dispose();
}
示例2: getImageBase64
import org.eclipse.swt.graphics.Image; //導入方法依賴的package包/類
private static String getImageBase64(Image image) {
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
ByteArrayOutputStream stream = new ByteArrayOutputStream();
imageLoader.save(stream, SWT.IMAGE_PNG);
return new String(Base64.getEncoder().encode(stream.toByteArray()));
}
示例3: rotate
import org.eclipse.swt.graphics.Image; //導入方法依賴的package包/類
/**
* Rotate an image
* @param image the source
* @param direction : SWT.LEFT will rotate by 90 degrees on the left, SWT.RIGHT will rotate by 90 degrees on the right, SWT.DOWN will rotate by 180 degrees.
* @return the rotated image
*/
private Image rotate(Image image, int direction) {
ImageData srcData = image.getImageData();
int bytesPerPixel = srcData.bytesPerLine / srcData.width;
int destBytesPerLine = (direction == SWT.DOWN) ? srcData.width * bytesPerPixel : srcData.height * bytesPerPixel;
byte[] newData = new byte[srcData.data.length];
boolean isAlpha = srcData.alphaData != null;
byte[] newAlphaData = null;
if (isAlpha) {
newAlphaData = new byte[srcData.alphaData.length];
}
ImageData imgData =
new ImageData((direction == SWT.DOWN) ? srcData.width : srcData.height, (direction == SWT.DOWN) ? srcData.height : srcData.width, srcData.depth,
srcData.palette, destBytesPerLine, newData);
if (isAlpha) {
imgData.alphaData = newAlphaData;
}
imgData.alpha = srcData.alpha;
for (int srcY = 0; srcY < srcData.height; srcY++) {
for (int srcX = 0; srcX < srcData.width; srcX++) {
int destX = 0, destY = 0;
switch (direction) {
case SWT.LEFT: // left 90 degrees
destX = srcY;
destY = srcData.width - srcX - 1;
break;
case SWT.RIGHT: // right 90 degrees
destX = srcData.height - srcY - 1;
destY = srcX;
break;
case SWT.DOWN: // 180 degrees
destX = srcData.width - srcX - 1;
destY = srcData.height - srcY - 1;
break;
}
imgData.setPixel(destX, destY, srcData.getPixel(srcX, srcY));
if (isAlpha) {
imgData.setAlpha(destX, destY, srcData.getAlpha(srcX, srcY));
}
}
}
return new Image(image.getDevice(), imgData);
}