Java Code Examples for org.eclipse.swt.graphics.ImageLoader#save()
The following examples show how to use
org.eclipse.swt.graphics.ImageLoader#save() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageWriter.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
public static void write(ImageFormat format, String path, List<UIImage> pages) throws TGFileFormatException { try { for(int i = 0; i < pages.size() ; i ++ ) { OutputStream stream = new FileOutputStream(new File(path + File.separator + "page-" + i + format.getExtension() )); Image image = ((SWTImage) pages.get(i)).getHandle(); ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] { image.getImageData() }; imageLoader.save(stream, format.getFormat() ); stream.flush(); stream.close(); } } catch (Throwable throwable) { throw new TGFileFormatException("Could not write song!.",throwable); } }
Example 2
Source File: ExportToImageManager.java From ermaster-b with Apache License 2.0 | 6 votes |
private void writePNGorGIF(Image image, String saveFilePath, String formatName) throws IOException, InterruptedException { try { ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image.getImageData() }; loader.save(saveFilePath, format); } catch (SWTException e) { // Eclipse 3.2 �ł́A PNG �� Unsupported or unrecognized format �ƂȂ邽�߁A // �ȉ��̑�֕��@���g�p���� // �������A���̕��@�ł͏�肭�o�͂ł��Ȃ������� e.printStackTrace(); BufferedImage bufferedImage = new BufferedImage( image.getBounds().width, image.getBounds().height, BufferedImage.TYPE_INT_RGB); drawAtBufferedImage(bufferedImage, image, 0, 0); ImageIO.write(bufferedImage, formatName, new File(saveFilePath)); } }
Example 3
Source File: AbstractGraphicalContentProvider.java From eclipsegraphviz with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} * * This default implementation relies on the * {@link #loadImage(Display, Point, Object)} method, subclasses are * encouraged to provide a more efficient implementation. */ public void saveImage(Display display, Point suggestedSize, Object input, IPath location, GraphicFileFormat fileFormat) throws CoreException { int swtFileFormat = getSWTFileFormat(fileFormat); Image toSave = loadImage(Display.getDefault(), new Point(0, 0), input); try { ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] { toSave.getImageData() }; ByteArrayOutputStream buffer = new ByteArrayOutputStream(200 * 1024); imageLoader.save(buffer, swtFileFormat); try { FileUtils.writeByteArrayToFile(location.toFile(), buffer.toByteArray()); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error saving image", e)); } } finally { toSave.dispose(); } }
Example 4
Source File: SaveImageAction.java From olca-app with Mozilla Public License 2.0 | 6 votes |
@Override public void run() { if (file == null) return; log.trace("export product graph as image: {}", file); ScalableRootEditPart editPart = (ScalableRootEditPart) editor.getGraphicalViewer().getRootEditPart(); IFigure rootFigure = editPart.getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle bounds = rootFigure.getBounds(); Image img = new Image(null, bounds.width, bounds.height); GC imageGC = new GC(img); Graphics graphics = new SWTGraphics(imageGC); rootFigure.paint(graphics); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = new ImageData[] { img.getImageData() }; imgLoader.save(file.getAbsolutePath(), SWT.IMAGE_PNG); }
Example 5
Source File: ExportImageAction.java From gef with Eclipse Public License 2.0 | 6 votes |
@Override public void run(IAction action) { FileDialog dialog = new FileDialog(getShell(), SWT.SAVE); dialog.setFileName("Cloud.png"); dialog.setText("Export PNG image to..."); String destFile = dialog.open(); if (destFile == null) return; File f = new File(destFile); if (f.exists()) { boolean confirmed = MessageDialog.openConfirm(getShell(), "File already exists", "The file '" + f.getName() + "' does already exist. Do you want to override it?"); if (!confirmed) return; } ImageLoader il = new ImageLoader(); try { il.data = new ImageData[] { getViewer().getCloud().getImageData() }; il.save(destFile, SWT.IMAGE_PNG); } catch (Exception e) { e.printStackTrace(); } }
Example 6
Source File: ExportToFileAction.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void run() { IFigure contents = railroadView.getContents(); if (contents != null) { FileDialog fileDialog = new FileDialog(this.railroadView.getSite().getShell(), SWT.SAVE); fileDialog.setFilterExtensions(new String[] { "*.png" }); fileDialog.setText("Choose diagram file"); String fileName = fileDialog.open(); if (fileName == null) { return; } Dimension preferredSize = contents.getPreferredSize(); Image image = new Image(Display.getDefault(), preferredSize.width + 2 * PADDING, preferredSize.height + 2 * PADDING); GC gc = new GC(image); SWTGraphics graphics = new SWTGraphics(gc); graphics.translate(PADDING, PADDING); graphics.translate(contents.getBounds().getLocation().getNegated()); contents.paint(graphics); ImageData imageData = image.getImageData(); ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] { imageData }; imageLoader.save(fileName, SWT.IMAGE_PNG); } }
Example 7
Source File: SwtImage.java From AppleCommander with GNU General Public License v2.0 | 6 votes |
/** * Save the image. */ public void save(OutputStream outputStream) throws IOException { ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] { imageData }; int format = SWT.IMAGE_PNG; if ("BMP".equals(getFileExtension())) { //$NON-NLS-1$ format = SWT.IMAGE_BMP; } else if ("RLE".equals(getFileExtension())) { //$NON-NLS-1$ format = SWT.IMAGE_BMP_RLE; } else if ("GIF".equals(getFileExtension())) { //$NON-NLS-1$ format = SWT.IMAGE_GIF; } else if ("ICO".equals(getFileExtension())) { //$NON-NLS-1$ format = SWT.IMAGE_ICO; } else if ("JPEG".equals(getFileExtension())) { //$NON-NLS-1$ format = SWT.IMAGE_JPEG; } else if ("PNG".equals(getFileExtension())) { //$NON-NLS-1$ format = SWT.IMAGE_PNG; } imageLoader.save(outputStream, format); }
Example 8
Source File: ImageInfo.java From ermasterr with Apache License 2.0 | 5 votes |
public void toImageData() throws InterruptedException, IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); // try { format = SWT.IMAGE_PNG; // final ImageLoader imgLoader = new ImageLoader(); imgLoader.data = new ImageData[] {image.getImageData()}; imgLoader.save(out, format); // // } catch (SWTException e) { // if (this.format == SWT.IMAGE_PNG) { // BufferedImage bufferedImage = new BufferedImage( // image.getBounds().width, image.getBounds().height, // BufferedImage.TYPE_INT_RGB); // // ImageUtils.drawAtBufferedImage(bufferedImage, image, 0, 0); // BufferedImage bufferedImage = // ImageUtils.convertToBufferedImage(image); // // String formatName = "png"; // // ImageIO.write(bufferedImage, formatName, out); // } else { // throw e; // } // } imageData = out.toByteArray(); }
Example 9
Source File: ImageWriter.java From logbook with MIT License | 5 votes |
/** * 指定されたimageを書き込みます。 * * @param image * 書き込むImage * @throws IOException */ public void write(Image image) throws IOException { try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(this.path, this.options))) { ImageLoader il = new ImageLoader(); il.data = new ImageData[] { image.getImageData() }; il.compression = this.compression; il.save(out, this.format); } }
Example 10
Source File: KettleXulLoader.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public InputStream getResourceAsStream( String resource ) { int height = iconHeight; int width = iconWidth; if ( resource.contains( ":" ) ) { // we have height/width overrides width = Integer.parseInt( resource.substring( resource.indexOf( ":" ) + 1, resource.indexOf( "#" ) ) ); height = Integer.parseInt( resource.substring( resource.indexOf( "#" ) + 1, resource.indexOf( "." ) ) ); resource = resource.substring( 0, resource.indexOf( ":" ) ) + resource.substring( resource.indexOf( "." ) ); } if ( SvgSupport.isSvgEnabled() && ( SvgSupport.isSvgName( resource ) || SvgSupport.isPngName( resource ) ) ) { InputStream in = null; try { in = super.getResourceAsStream( SvgSupport.toSvgName( resource ) ); // load SVG SvgImage svg = SvgSupport.loadSvgImage( in ); SwtUniversalImage image = new SwtUniversalImageSvg( svg ); Display d = Display.getCurrent() != null ? Display.getCurrent() : Display.getDefault(); // write to png Image result = image.getAsBitmapForSize( d, width, height ); ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { result.getImageData() }; ByteArrayOutputStream out = new ByteArrayOutputStream(); loader.save( out, SWT.IMAGE_PNG ); image.dispose(); return new ByteArrayInputStream( out.toByteArray() ); } catch ( Throwable ignored ) { // any exception will result in falling back to PNG } finally { IOUtils.closeQuietly( in ); } resource = SvgSupport.toPngName( resource ); } return super.getResourceAsStream( resource ); }
Example 11
Source File: MImageSWTImpl.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
@Override public InputStream getInputStream() throws IOException { try (ByteArrayOutputStream output = new ByteArrayOutputStream();) { final ImageLoader imageLoader = new ImageLoader(); imageLoader.data = new ImageData[] {image, }; imageLoader.save(output, SWT.IMAGE_PNG); return new ByteArrayInputStream(output.toByteArray()); } }
Example 12
Source File: SankeyImageAction.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public void run() { try { ImageLoader imgLoader = new ImageLoader(); imgLoader.data = new ImageData[] { image.getImageData() }; imgLoader.save(file.getAbsolutePath(), SWT.IMAGE_PNG); } catch (Exception e) { log.error("Failed to write image", e); } }
Example 13
Source File: ExportToImageManager.java From erflute with Apache License 2.0 | 5 votes |
private void writeJPGorBMP(Image image, String saveFilePath, int format) throws IOException { final ImageData[] imgData = new ImageData[1]; imgData[0] = image.getImageData(); final ImageLoader imgLoader = new ImageLoader(); imgLoader.data = imgData; imgLoader.save(saveFilePath, format); }
Example 14
Source File: ExportToImageManager.java From erflute with Apache License 2.0 | 5 votes |
private void writePNGorGIF(Image image, String saveFilePath, String formatName) throws IOException, InterruptedException { try { final ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image.getImageData() }; loader.save(saveFilePath, format); } catch (final SWTException e) { e.printStackTrace(); final BufferedImage bufferedImage = new BufferedImage(image.getBounds().width, image.getBounds().height, BufferedImage.TYPE_INT_RGB); drawAtBufferedImage(bufferedImage, image, 0, 0); ImageIO.write(bufferedImage, formatName, new File(saveFilePath)); } }
Example 15
Source File: ImagesOnFileSystemRegistry.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public URL getImageURL(ImageDescriptor descriptor) { if (fTempDir == null) return null; URL url= fURLMap.get(descriptor); if (url != null) return url; File imageFile= getNewFile(); ImageData imageData= descriptor.getImageData(); if (imageData == null) { return null; } ImageLoader loader= new ImageLoader(); loader.data= new ImageData[] { imageData }; loader.save(imageFile.getAbsolutePath(), SWT.IMAGE_PNG); try { url= imageFile.toURI().toURL(); fURLMap.put(descriptor, url); return url; } catch (MalformedURLException e) { JavaPlugin.log(e); } return null; }
Example 16
Source File: ExportToImageManager.java From ermaster-b with Apache License 2.0 | 5 votes |
private void writeJPGorBMP(Image image, String saveFilePath, int format) throws IOException { ImageData[] imgData = new ImageData[1]; imgData[0] = image.getImageData(); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = imgData; imgLoader.save(saveFilePath, format); }
Example 17
Source File: ImageCaptureExample.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Demonstrate capturing the pages of a print to in-memory images. * * @param args * command-line arguments (ignored) */ public static void main(String[] args) { Display display = new Display(); Point displayDPI = display.getDPI(); display.dispose(); Printer printer = new Printer(new PrinterData()); Point printerDPI = printer.getDPI(); try { PrintJob job = new PrintJob("ImageCapture.java", createPrint()); PrintPiece[] pages = PaperClips.getPages(job, printer); ImageLoader imageLoader = new ImageLoader(); for (int i = 0; i < pages.length; i++) { PrintPiece page = pages[i]; Point pageSize = page.getSize(); pageSize.x = pageSize.x * displayDPI.x / printerDPI.x; pageSize.y = pageSize.y * displayDPI.y / printerDPI.y; ImageData pageImage = captureImageData(printer, page, pageSize); // Do something with the image pageImage.scanlinePad = 1; imageLoader.data = new ImageData[] { pageImage }; imageLoader.save(getImageName(i), SWT.IMAGE_JPEG); } } finally { printer.dispose(); } }
Example 18
Source File: ImageUtils.java From WebpifyYourAndroidApp with Apache License 2.0 | 4 votes |
public static void saveToJpg(ImageData image, int compression, File f) { ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image }; loader.compression = compression; loader.save(f.getAbsolutePath(), SWT.IMAGE_JPEG); }
Example 19
Source File: AbstractVTestCase.java From nebula with Eclipse Public License 2.0 | 4 votes |
private void capture(Rectangle bounds, String suffix) { GC gc = new GC(display); Image image = new Image(display, bounds); gc.copyArea(image, bounds.x, bounds.y); gc.dispose(); ImageData[] da = new ImageData[] { image.getImageData() }; image.dispose(); ImageLoader il = new ImageLoader(); il.data = da; StringBuilder sb = new StringBuilder(); if (capturePath != null && capturePath.length() > 0) { sb.append(capturePath); } else { sb.append(System.getProperty("user.home")); } File path = new File(sb.toString()); if (!path.exists()) { path.mkdirs(); } sb.append(File.separator); sb.append(getName()); if (suffix != null && suffix.length() > 0) { sb.append("-").append(suffix); } switch (captureFormat) { case SWT.IMAGE_BMP: sb.append(".bmp"); break; case SWT.IMAGE_GIF: sb.append(".gif"); break; case SWT.IMAGE_ICO: sb.append(".ico"); break; case SWT.IMAGE_JPEG: sb.append(".jpg"); break; case SWT.IMAGE_PNG: sb.append(".png"); break; case SWT.IMAGE_TIFF: sb.append(".tiff"); break; default: captureFormat = SWT.IMAGE_PNG; sb.append(".png"); break; } il.save(sb.toString(), captureFormat); }
Example 20
Source File: AnalysisView.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * Given a GEF GraphicalViewer, this method creates a save file dialog and * will save the contents of the viewer as an image file. Supported * extensions include PNG, JPG, and BMP. * * @param viewer * The GraphicalViewer to save as an image. */ protected static void saveViewerImage(GraphicalViewer viewer) { // Store the allowed extensions in a HashMap. HashMap<String, Integer> extensions = new HashMap<String, Integer>(4); extensions.put("png", SWT.IMAGE_PNG); extensions.put("jpg", SWT.IMAGE_JPEG); extensions.put("bmp", SWT.IMAGE_BMP); // Make the array of strings needed to pass to the file dialog. String[] extensionStrings = new String[extensions.keySet().size()]; int i = 0; for (String extension : extensions.keySet()) { extensionStrings[i++] = "*." + extension; } // Create the file save dialog. FileDialog fileDialog = new FileDialog(viewer.getControl().getShell(), SWT.SAVE); fileDialog.setFilterExtensions(extensionStrings); fileDialog.setOverwrite(true); // Get the path of the new/overwritten image file. String path = fileDialog.open(); // Return if the user cancelled. if (path == null) { return; } // Get the image type to save from the path's extension. String[] splitPath = path.split("\\."); int extensionSWT = extensions.get(splitPath[splitPath.length - 1]); // Get the root EditPart and its draw2d Figure. SimpleRootEditPart rootEditPart = (SimpleRootEditPart) viewer .getRootEditPart(); IFigure figure = rootEditPart.getFigure(); // Get the image from the Figure. org.eclipse.draw2d.geometry.Rectangle bounds = figure.getBounds(); Image image = new Image(null, bounds.width, bounds.height); GC gc = new GC(image); SWTGraphics g = new SWTGraphics(gc); figure.paint(g); g.dispose(); gc.dispose(); // Save the file. ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image.getImageData() }; loader.save(path, extensionSWT); image.dispose(); return; }