import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
protected EmulatorSkin skin;
protected EmulatorConfig config;
- private Shell shell;
+ protected Shell shell;
private ScrolledComposite scrollComposite;
protected Canvas canvasShot;
private void clickShutter() throws ScreenShotException {
Image maskImage = skin.getDisplayCanvas().getMaskImage();
- if (maskImage != null) {
+ if (maskImage != null && skin.getDisplayCanvas().getRegion() != null) {
capture(SkinUtil.getMaskDataForImage(shell.getDisplay(), maskImage));
} else {
capture(null);
fileDialog.setOverwrite(true);
String filePath = fileDialog.open();
- saveFile(filePath, fileDialog);
+ saveImageFile(filePath, fileDialog);
}
});
}
});
- ImageLoader loader = new ImageLoader();
- ImageData shotData = imageShot.getImageData();
-
- if (SwtUtil.isWindowsPlatform()) {
- /* convert to RGBA */
- shotData.palette =
- new PaletteData(0xFF000000, 0x00FF0000, 0x0000FF00);
- }
-
- loader.data = new ImageData[] { shotData };
-
- if (SwtUtil.isLinuxPlatform() == true &&
- SwtUtil.is64bitPlatform() == true) {
- /* use Python for Ubuntu 64bit */
- FileOutputStream fos = null;
- String fileName = "screenshot" +
- skin.config.getArgInt(ArgsConstants.VM_BASE_PORT) + ".png";
-
- try {
- fos = new FileOutputStream(fileName, false);
- } catch (FileNotFoundException ee) {
- logger.log(Level.SEVERE, ee.getMessage(), ee);
- SkinUtil.openMessage(shell, null,
- "Failed to copy to clipboard : \n" + ee.getMessage(),
- SWT.ICON_ERROR, config);
- return;
- }
-
- loader.save(fos, SWT.IMAGE_PNG);
- IOUtil.close(fos);
-
- ProcessBuilder procPy = new ProcessBuilder();
- procPy.command("python", "clipboard.py", fileName);
-
- logger.info(procPy.command().toString());
-
- try {
- procPy.start();
- } catch (Exception ee) {
- logger.log(Level.SEVERE, ee.getMessage(), ee);
- SkinUtil.openMessage(shell, null,
- "Failed to copy to clipboard : \n" + ee.getMessage(),
- SWT.ICON_ERROR, config);
- }
- } else {
- ByteArrayOutputStream bao = new ByteArrayOutputStream();
- loader.save(bao, SWT.IMAGE_PNG);
-
- ImageData pngData = new ImageData(
- new ByteArrayInputStream(bao.toByteArray()));
-
- Object[] imageObject = new Object[] { pngData };
-
- Transfer[] transfer = new Transfer[] { ImageTransfer.getInstance() };
- Clipboard clipboard = new Clipboard(parent.getDisplay());
- clipboard.setContents(imageObject, transfer);
-
- clipboard.dispose();
- }
+ copyImageToClipboard(imageShot);
}
});
", y : " + skin.getEmulatorSkinState().getCurrentResolutionHeight() * (int)MAX_SCALE_MULTIPLE + " ");
}
- private void saveFile(String fileFullPath, FileDialog fileDialog) {
+ private void copyImageToClipboard(Image image) {
+ ImageData imageData = image.getImageData();
+
+ if (SwtUtil.isLinuxPlatform() == true &&
+ SwtUtil.is64bitPlatform() == true) {
+ /* use Python for Ubuntu 64bit */
+ FileOutputStream fos = null;
+ String fileName = "screenshot" +
+ skin.config.getArgInt(ArgsConstants.VM_BASE_PORT) + ".png";
+
+ try {
+ fos = new FileOutputStream(fileName, false);
+ } catch (FileNotFoundException ee) {
+ logger.log(Level.SEVERE, ee.getMessage(), ee);
+ SkinUtil.openMessage(shell, null,
+ "Failed to copy to clipboard : \n" + ee.getMessage(),
+ SWT.ICON_ERROR, config);
+ return;
+ }
+
+ ImageLoader loader = new ImageLoader();
+ loader.data = new ImageData[] { imageData };
+
+ loader.save(fos, SWT.IMAGE_PNG);
+ IOUtil.close(fos);
+
+ ProcessBuilder procPy = new ProcessBuilder();
+ procPy.command("python", "clipboard.py", fileName);
+
+ logger.info(procPy.command().toString());
+
+ try {
+ procPy.start();
+ } catch (Exception ee) {
+ logger.log(Level.SEVERE, ee.getMessage(), ee);
+ SkinUtil.openMessage(shell, null,
+ "Failed to copy to clipboard : \n" + ee.getMessage(),
+ SWT.ICON_ERROR, config);
+ }
+ } else if (SwtUtil.isWindowsPlatform() == true &&
+ skin.getDisplayCanvas().getRegion() != null) {
+ /* use java.awt to transfer a transparent background image */
+ String fileName = "screenshot" +
+ skin.config.getArgInt(ArgsConstants.VM_BASE_PORT) + ".png";
+
+ try {
+ saveImageFileInternal(fileName, SWT.IMAGE_PNG, imageData);
+ } catch (Exception ee) {
+ logger.log(Level.SEVERE, ee.getMessage(), ee);
+ SkinUtil.openMessage(shell, null,
+ "Failed to copy to clipboard : \n" + ee.getMessage(),
+ SWT.ICON_ERROR, config);
+ return;
+ }
+
+ ClipbrdTransfer.write(fileName);
+ } else {
+ /* use SWT */
+ ImageLoader loader = new ImageLoader();
+
+ if (SwtUtil.isWindowsPlatform() == true) {
+ /* convert to RGBA */
+ imageData.palette =
+ new PaletteData(0xFF000000, 0x00FF0000, 0x0000FF00);
+ }
+ loader.data = new ImageData[] { imageData };
+
+ ByteArrayOutputStream bao = new ByteArrayOutputStream();
+ loader.save(bao, SWT.IMAGE_PNG);
+
+ ImageData pngData = new ImageData(
+ new ByteArrayInputStream(bao.toByteArray()));
+
+ Object[] imageObject = new Object[] { pngData };
+
+ Transfer[] transfer = new Transfer[] { ImageTransfer.getInstance() };
+ Clipboard clipboard = new Clipboard(shell.getDisplay());
+ clipboard.setContents(imageObject, transfer);
+
+ clipboard.dispose();
+ }
+ }
+
+ private void saveImageFile(String fileFullPath, FileDialog fileDialog) {
if (null == fileFullPath) {
return;
}
"Use correct file name.", SWT.ICON_WARNING, config);
String path = fileDialog.open();
- saveFile(path, fileDialog);
+ saveImageFile(path, fileDialog);
}
}
- FileOutputStream fos = null;
-
try {
if (StringUtil.isEmpty(format)) {
if (fileFullPath.endsWith(".")) {
}
}
- ImageLoader loader = new ImageLoader();
- loader.data = new ImageData[] { imageShot.getImageData() };
-
if (StringUtil.isEmpty(format) || format.equalsIgnoreCase("png")) {
- fos = new FileOutputStream(fileFullPath, false);
- loader.save(fos, SWT.IMAGE_PNG);
+ saveImageFileInternal(fileFullPath,
+ SWT.IMAGE_PNG, imageShot.getImageData());
} else if (format.equalsIgnoreCase("jpg") || format.equalsIgnoreCase("jpeg")) {
- fos = new FileOutputStream(fileFullPath, false);
- loader.save(fos, SWT.IMAGE_JPEG);
+ saveImageFileInternal(fileFullPath,
+ SWT.IMAGE_JPEG, imageShot.getImageData());
} else if (format.equalsIgnoreCase("bmp")) {
- fos = new FileOutputStream(fileFullPath, false);
- loader.save(fos, SWT.IMAGE_BMP);
+ saveImageFileInternal(fileFullPath,
+ SWT.IMAGE_BMP, imageShot.getImageData());
} else {
SkinUtil.openMessage(shell, null,
"Use the specified image formats. (PNG / JPG / JPEG / BMP)",
SWT.ICON_WARNING, config);
String path = fileDialog.open();
- saveFile(path, fileDialog);
+ saveImageFile(path, fileDialog);
}
- } catch (FileNotFoundException ex) {
- logger.log(Level.WARNING, "Use correct file name.", ex);
- SkinUtil.openMessage(shell, null,
- "Use correct file name.", SWT.ICON_WARNING, config);
-
- String path = fileDialog.open();
- saveFile(path, fileDialog);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Fail to save this image file.", ex);
SkinUtil.openMessage(shell, null,
"Fail to save this image file.", SWT.ERROR, config);
String path = fileDialog.open();
- saveFile(path, fileDialog);
- } finally {
- IOUtil.close(fos);
+ saveImageFile(path, fileDialog);
+ }
+ }
+
+ private void saveImageFileInternal(String filePath,
+ int imageFormat, ImageData imageData) throws Exception {
+ ImageLoader loader = new ImageLoader();
+
+ Image maskImage = skin.getDisplayCanvas().getMaskImage();
+ if (maskImage != null && skin.getDisplayCanvas().getRegion() != null &&
+ SwtUtil.isWindowsPlatform() == true) {
+ /* When save an PNG image with mask data on Windows,
+ * transparent background cannot be applied to image file.
+ * So, to handle alpha channel, transparent pixel field in ImageData class
+ * should get a color key value from background area. */
+
+ final int colorKey = imageData.palette.getPixel(new RGB(255, 0, 255));
+ final int fakeKey = imageData.palette.getPixel(new RGB(255, 1, 255));
+ SkinUtil.setColorKeyFromMask(shell.getDisplay(),
+ colorKey, fakeKey, maskImage.getImageData(), imageData);
+
+ imageData.transparentPixel = colorKey;
+ imageData.maskData = null;
}
+
+ loader.data = new ImageData[] { imageData };
+
+ FileOutputStream fos = new FileOutputStream(filePath, false);
+ loader.save(fos, imageFormat);
+
+ IOUtil.close(fos);
}
public void open() throws ScreenShotException {