Java Code Examples for org.eclipse.swt.graphics.Image#getImageData()
The following examples show how to use
org.eclipse.swt.graphics.Image#getImageData() .
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: ExportToImageManager.java From ermaster-b with Apache License 2.0 | 6 votes |
private void drawAtBufferedImage(BufferedImage bimg, Image image, int x, int y) throws InterruptedException { ImageData data = image.getImageData(); for (int i = 0; i < image.getBounds().width; i++) { for (int j = 0; j < image.getBounds().height; j++) { int tmp = 4 * (j * image.getBounds().width + i); if (data.data.length > tmp + 2) { int r = 0xff & data.data[tmp + 2]; int g = 0xff & data.data[tmp + 1]; int b = 0xff & data.data[tmp]; bimg.setRGB(i + x, j + y, 0xFF << 24 | r << 16 | g << 8 | b << 0); } this.doPostTask(); } } }
Example 2
Source File: ExportToImageManager.java From erflute with Apache License 2.0 | 6 votes |
private void drawAtBufferedImage(BufferedImage bimg, Image image, int x, int y) throws InterruptedException { final ImageData data = image.getImageData(); for (int i = 0; i < image.getBounds().width; i++) { for (int j = 0; j < image.getBounds().height; j++) { final int tmp = 4 * (j * image.getBounds().width + i); if (data.data.length > tmp + 2) { final int r = 0xff & data.data[tmp + 2]; final int g = 0xff & data.data[tmp + 1]; final int b = 0xff & data.data[tmp]; bimg.setRGB(i + x, j + y, 0xFF << 24 | r << 16 | g << 8 | b << 0); } doPostTask(); } } }
Example 3
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 4
Source File: GamaIcons.java From gama with GNU General Public License v3.0 | 6 votes |
public static GamaIcon createColorIcon(final String s, final GamaUIColor gcolor, final int width, final int height) { final String name = COLOR_PREFIX + s; GamaIcon icon = getInstance().getIcon(s); if (icon == null) { // Color color = gcolor.color(); // RGB c = new RGB(color.getRed(), color.getGreen(), // color.getBlue()); final Image image = new Image(WorkbenchHelper.getDisplay(), width, height); final GC gc = new GC(image); gc.setAntialias(SWT.ON); gc.setBackground(gcolor.color()); gc.fillRoundRectangle(0, 0, width, height, width / 3, height / 3); gc.dispose(); final ImageData data = image.getImageData(); data.transparentPixel = data.palette.getPixel(new RGB(255, 255, 255)); icon = new GamaIcon(name); getInstance().putImageInCache(name, new Image(WorkbenchHelper.getDisplay(), data)); image.dispose(); getInstance().putIconInCache(name, icon); } return icon; }
Example 5
Source File: ImageUtil.java From hop with Apache License 2.0 | 5 votes |
public static Image makeImageTransparent( Display display, Image tempImage, RGB transparentColor ) { ImageData imageData = tempImage.getImageData(); int pixelIndex = imageData.palette.getPixel( transparentColor ); imageData.transparentPixel = pixelIndex; Image image = new Image( display, imageData ); tempImage.dispose(); return image; }
Example 6
Source File: DateChooserCombo.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Sets a new image to display on the button, replacing the default one. * * @param image new image */ public void setImage(Image image) { checkWidget(); if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); GridData buttonLayout = (GridData) button.getLayoutData(); if (WIN32) { ImageData id = image.getImageData(); buttonLayout.widthHint = id.width + 4; buttonLayout.heightHint = id.height + 6; } button.setImage(image); pack(); }
Example 7
Source File: ImageUtil.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static Image makeImageTransparent( Display display, Image tempImage, RGB transparentColor ) { ImageData imageData = tempImage.getImageData(); int pixelIndex = imageData.palette.getPixel( transparentColor ); imageData.transparentPixel = pixelIndex; Image image = new Image( display, imageData ); tempImage.dispose(); return image; }
Example 8
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 9
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 10
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 11
Source File: ImageViewerTest.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
@Test public void testSetImageDatas() { Image image = new Image( displayHelper.getDisplay(), 2, 2 ); ImageData imageData = image.getImageData(); imageViewer.setImageDatas( imageData ); assertThat( imageViewer.getImageDatas() ).containsOnly( imageData ); }
Example 12
Source File: ImageCache.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * @param key the key of the image that should be decorated (relative path to the plugin directory) * @param decoration the key of the image that should be decorated (relative path to the plugin directory) */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public IImageHandle getImageDecorated(String key, String decoration, int decorationLocation, String secondDecoration, int secondDecorationLocation) { Display display = Display.getCurrent(); if (display == null) { Log.log("This method should only be called in a UI thread."); } Object cacheKey = new Tuple4(key, decoration, decorationLocation, "imageDecoration"); if (secondDecoration != null) { //Also add the second decoration to the cache key. cacheKey = new Tuple3(cacheKey, secondDecoration, secondDecorationLocation); } Image image = getFromImageHash(cacheKey); if (image == null) { //Note that changing the image data gotten here won't affect the original image. ImageData baseImageData = (ImageData) get(key).getImageData(); image = decorateImage(decoration, decorationLocation, display, baseImageData); if (secondDecoration != null) { image = decorateImage(secondDecoration, secondDecorationLocation, display, image.getImageData()); } image = putOnImageHash(cacheKey, image); } final Image computed = image; return new IImageHandle() { @Override public Object getImageData() { return computed.getImageData(); } @Override public Object getImage() { return computed; } }; }
Example 13
Source File: ConsistencyAction.java From saros with GNU General Public License v2.0 | 4 votes |
private static ImageData modifyAlphaChannel(Image image, int alpha) { if (alpha < 0) alpha = 0; if (alpha > 255) alpha = 255; ImageData data = image.getImageData(); for (int x = 0; x < data.width; x++) { for (int y = 0; y < data.height; y++) { int a = data.getAlpha(x, y); // value depends on the image, must be determined empirically if (a <= MIN_ALPHA_VALUE) continue; data.setAlpha(x, y, alpha); } } return data; }
Example 14
Source File: BreadcrumbItemDropDown.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
protected void drawCompositeImage(int width, int height) { Display display = fParentComposite.getDisplay(); Image image = new Image(display, ARROW_SIZE, ARROW_SIZE * 2); GC gc = new GC(image); Color triangle = createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 20, display); Color aliasing = createColor(SWT.COLOR_LIST_FOREGROUND, SWT.COLOR_LIST_BACKGROUND, 30, display); gc.setBackground(triangle); if (fLTR) { gc.fillPolygon(new int[] { mirror(0), 0, mirror(ARROW_SIZE), ARROW_SIZE, mirror(0), ARROW_SIZE * 2}); } else { gc.fillPolygon(new int[] { ARROW_SIZE, 0, 0, ARROW_SIZE, ARROW_SIZE, ARROW_SIZE * 2}); } gc.setForeground(aliasing); gc.drawLine(mirror(0), 1, mirror(ARROW_SIZE - 1), ARROW_SIZE); gc.drawLine(mirror(ARROW_SIZE - 1), ARROW_SIZE, mirror(0), ARROW_SIZE * 2 - 1); gc.dispose(); triangle.dispose(); aliasing.dispose(); ImageData imageData = image.getImageData(); for (int y = 1; y < ARROW_SIZE; y++) { for (int x = 0; x < y; x++) { imageData.setAlpha(mirror(x), y, 255); } } for (int y = 0; y < ARROW_SIZE; y++) { for (int x = 0; x <= y; x++) { imageData.setAlpha(mirror(x), ARROW_SIZE * 2 - y - 1, 255); } } int offset = fLTR ? 0 : -1; drawImage(imageData, (width / 2) - (ARROW_SIZE / 2) + offset, (height / 2) - ARROW_SIZE - 1); image.dispose(); }
Example 15
Source File: DTable2MTableConverter.java From M2Doc with Eclipse Public License 1.0 | 4 votes |
/** * Converts the given {@link DLine} to a {@link List} of {@link MRow}. * * @param table * the {@link DTable} to convert * @param columnStyles * the style mapping * @param line * the {@link DLine} to convert * @param depth * the current depth of the table line * @param withHeader * <code>true</code> to generate header {@link MStyle}, <code>false</code> otherwise * @return the {@link List} of converted {@link MRow} */ private List<MRow> convertRow(DTable table, final Map<Integer, DTableElementStyle> columnStyles, DLine line, int depth, boolean withHeader) { final List<MRow> res = new ArrayList<>(); if (line.isVisible()) { final MRow row = new MRowImpl(); res.add(row); // A header cell is inserted final MList headerCellContent = new MListImpl(); if (depth > 0) { final MText intentation = new MTextImpl(getIntentation(depth), getHeaderStyle(withHeader)); headerCellContent.add(intentation); } final Image image = adapterFactoryLabelProvider.getImage(line.getTarget()); final MImage mImage = new MImageSWTImpl(image.getImageData()); headerCellContent.add(mImage); final MText mHeaderText = new MTextImpl(line.getLabel(), getHeaderStyle(withHeader)); headerCellContent.add(mHeaderText); final MCell mHeaderColumnCell = new MCellImpl(headerCellContent, getHeaderBackgroundColor(withHeader)); row.getCells().add(mHeaderColumnCell); // Retrieve row style to apply to non styled cells final DTableElementStyle rowStyle = line.getCurrentStyle(); // Initialize the row cells for (int colIdx = 0; colIdx < table.getColumns().size(); colIdx++) { final DTableElementStyle style; if (rowStyle != null) { style = rowStyle; } else { style = columnStyles.get(colIdx); } if (style != null) { row.getCells().add(new MCellImpl(null, convertColor(style.getBackgroundColor()))); } else { row.getCells().add(new MCellImpl(null, null)); } } for (DCell dcell : line.getCells()) { setCellContent(table, columnStyles, row, rowStyle, dcell); } for (DLine child : line.getLines()) { res.addAll(convertRow(table, columnStyles, child, depth + 1, withHeader)); } } return res; }
Example 16
Source File: AboutDialog.java From devstudio-tooling-ei with Apache License 2.0 | 4 votes |
protected Control createDialogArea(Composite parent) { Image logoImage = ResourceManager.getPluginImage("org.wso2.developerstudio.eclipse.platform.ui", "icons/ei-tooling-logo.png"); logoWidth = logoImage.getImageData().width; logoHeight = logoImage.getImageData().height; parent.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); Composite dialogArea = (Composite) super.createDialogArea(parent); dialogArea.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); dialogArea.setSize(new Point(logoWidth, logoHeight * 4 - 60)); Composite composite = new Composite(dialogArea, SWT.BORDER); composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); composite.setLayout(new GridLayout(1, false)); composite.setSize(new Point(logoWidth + 45, logoHeight * 4 - 60)); GridData gd_composite = new GridData(SWT.CENTER, SWT.TOP, true, true, 1, 1); gd_composite.widthHint = logoWidth + 45; gd_composite.heightHint = logoHeight * 4 - 60; composite.setLayoutData(gd_composite); Label lblDevsLogo = new Label(composite, SWT.NONE); lblDevsLogo.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); lblDevsLogo.setImage(logoImage); GridData gdDevsLogo = new GridData(SWT.CENTER, SWT.TOP, false, false, 1, 1); gdDevsLogo.widthHint = logoWidth; gdDevsLogo.heightHint = logoHeight; lblDevsLogo.setLayoutData(gdDevsLogo); Label lblVersion = new Label(composite, SWT.NONE); GridData versionGrid = new GridData(); versionGrid.horizontalIndent = 25; lblVersion.setLayoutData(versionGrid); lblVersion.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BORDER)); lblVersion.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); lblVersion.setText(VERSION); Label lblLicense = new Label(composite, SWT.NONE); GridData licenseGrid = new GridData(); licenseGrid.horizontalIndent = 25; lblLicense.setLayoutData(licenseGrid); lblLicense.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); lblLicense.setText(LICENSED); Link linkDevStudioUrl = new Link(composite, SWT.NONE); GridData urlGrid = new GridData(); urlGrid.horizontalIndent = 25; linkDevStudioUrl.setLayoutData(urlGrid); linkDevStudioUrl.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); linkDevStudioUrl.setText("Visit :<a>" + URL + "</a>"); linkDevStudioUrl.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { org.eclipse.swt.program.Program.launch(URL); } }); addProductIcons(composite); return dialogArea; }
Example 17
Source File: Transition.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Starts the transition from the <i>from</i> image to the <i>to</i> image * drawing the effect on the graphics context object <i>gc</i>. The <i>direction</i> * parameter determines the direction of the transition in degrees starting from 0 * as the right direction and increasing in counter clock wise direction. * * @param from is the image to start the transition from * @param to is the image to end the transition to * @param canvas is the canvas object to draw the transition on * @param direction determines the direction of the transition in degrees */ public final void start(final Image from, final Image to, final Canvas canvas, final double direction) { //_transitionManager.isAnyTransitionInProgress.setValue(true); boolean flag = true; long t0 = System.currentTimeMillis(); long dt = 0; long ttemp = 0; _t = 0; //prepare transition background ImageData fromData = from.getImageData(); final Image xitionBg = new Image(Display.getCurrent(), fromData.width, fromData.height); GC xitionBgGC = new GC(xitionBg); xitionBgGC.setBackground(_transitionManager.backgroundColor); xitionBgGC.fillRectangle(0, 0, fromData.width, fromData.height); if( null != _transitionManager.backgroundImage ) { ImageData imgData = _transitionManager.backgroundImage.getImageData(); xitionBgGC.drawImage(_transitionManager.backgroundImage , 0, 0, imgData.width, imgData.height , 0, 0, fromData.width, fromData.height); } xitionBgGC.dispose(); final TransitionPainter transitionPainter = new TransitionPainter(canvas, from, to, direction, xitionBg); transitionPainter.paintTransition( TransitionPainter.TRANSITION_INIT); //while(!_transitionManager.isCurrentTransitionCanceled.get() // && _t <= _T) { while(_t <= _T) { ttemp = System.currentTimeMillis() - t0; dt = ttemp - _t; if(flag) _t = ttemp; //this condition is to make sure that the //required fps (or less) is satisfied and //not more if(dt >= _dt) { if(_t <= _T) { transitionPainter.paintTransition( TransitionPainter.TRANSITION_STEP); } else { transitionPainter.paintTransition( TransitionPainter.TRANSITION_END); } flag = true; doEvents(); } else { try { flag = false; Thread.sleep(_dt - dt); } catch (InterruptedException e) { e.printStackTrace(); } } } xitionBg.dispose(); //_transitionManager.isAnyTransitionInProgress.setValue(false); }
Example 18
Source File: AnalysisView.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * Given an SWT Canvas, this method creates a save file dialog and will save * the Canvas as an image file. Supported extensions include PNG, JPG, and * BMP. * * @param canvas * The Canvas to save as an image. */ protected static void saveCanvasImage(Canvas canvas) { // FIXME - It's possible to get a graphical glitch where there are black // pixels at the bottom of the image. My guess is that the GC never // actually bothers to paint because that part is not visible on the // screen. Currently, this issue is unresolved. // 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(canvas.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 image from the canvas. Rectangle bounds = canvas.getBounds(); Image image = new Image(null, bounds.width, bounds.height); GC gc = new GC(image); // SWT XYGraph uses this method to center the saved image. canvas.print(gc); gc.dispose(); // Save the file. ImageLoader loader = new ImageLoader(); loader.data = new ImageData[] { image.getImageData() }; loader.save(path, extensionSWT); image.dispose(); return; }
Example 19
Source File: DefaultTableHeaderRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ public ImageData getImageData() { Image img = new Image(Display.getCurrent(), this.getClass().getResourceAsStream(rscString)); return img.getImageData(); }
Example 20
Source File: PrintUtils.java From nebula with Eclipse Public License 2.0 | 2 votes |
/** * * @param image The image of the chart that should be printed. * @return The size of the image representation of the chart that * should be printed. */ public static Rectangle getVisibleGanttChartArea(Image image) { return new Rectangle(0, 0, image.getImageData().width, image.getImageData().height); }