java.awt.Image Java Examples
The following examples show how to use
java.awt.Image.
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: WTrayIconPeer.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
synchronized void updateNativeImage(Image image) { if (isDisposed()) return; boolean autosize = ((TrayIcon)target).isImageAutoSize(); BufferedImage bufImage = new BufferedImage(TRAY_ICON_WIDTH, TRAY_ICON_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics2D gr = bufImage.createGraphics(); if (gr != null) { try { gr.setPaintMode(); gr.drawImage(image, 0, 0, (autosize ? TRAY_ICON_WIDTH : image.getWidth(observer)), (autosize ? TRAY_ICON_HEIGHT : image.getHeight(observer)), observer); createNativeImage(bufImage); updateNativeIcon(!firstUpdate); if (firstUpdate) firstUpdate = false; } finally { gr.dispose(); } } }
Example #2
Source File: TranslucentWindowPainter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Updates the window associated with the painter. * * @param repaint indicates if the window should be completely repainted * to the back buffer using {@link java.awt.Window#paintAll} before update. */ public void updateWindow(boolean repaint) { boolean done = false; Image bb = getBackBuffer(repaint); while (!done) { if (repaint) { Graphics2D g = (Graphics2D)bb.getGraphics(); try { window.paintAll(g); } finally { g.dispose(); } } done = update(bb); if (!done) { repaint = true; bb = getBackBuffer(true); } } }
Example #3
Source File: LUTCompareTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws IOException { Image img = createTestImage(); Toolkit tk = Toolkit.getDefaultToolkit(); LUTCompareTest o = new LUTCompareTest(img); tk.prepareImage(img, -1, -1, o); while(!o.isImageReady()) { synchronized(lock) { try { lock.wait(200); } catch (InterruptedException e) { } } } checkResults(img); }
Example #4
Source File: DOMNodeAnnotator.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void annotate(Node node, Image badge) { int nodeId = node.getNodeId(); if (badge == null) { badges.remove(nodeId); } else { badges.put(node.getNodeId(), badge); } Page page = PageInspector.getDefault().getPage(); if (page instanceof WebKitPageModel) { WebKitPageModel pageModel = (WebKitPageModel)page; DOMNode domNode = pageModel.getNode(node.getNodeId()); if (domNode != null) { domNode.updateIcon(); } } }
Example #5
Source File: LUTCompareTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws IOException { Image img = createTestImage(); Toolkit tk = Toolkit.getDefaultToolkit(); LUTCompareTest o = new LUTCompareTest(img); tk.prepareImage(img, -1, -1, o); while(!o.isImageReady()) { synchronized(lock) { try { lock.wait(200); } catch (InterruptedException e) { } } } checkResults(img); }
Example #6
Source File: TranslucentWindowPainter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Updates the window associated with the painter. * * @param repaint indicates if the window should be completely repainted * to the back buffer using {@link java.awt.Window#paintAll} before update. */ public void updateWindow(boolean repaint) { boolean done = false; Image bb = getBackBuffer(repaint); while (!done) { if (repaint) { Graphics2D g = (Graphics2D)bb.getGraphics(); try { window.paintAll(g); } finally { g.dispose(); } } done = update(bb); if (!done) { repaint = true; bb = getBackBuffer(true); } } }
Example #7
Source File: SunGraphics2D.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) { final int scale = SurfaceManager.getImageScale(img); sx1 = Region.clipScale(sx1, scale); sx2 = Region.clipScale(sx2, scale); sy1 = Region.clipScale(sy1, scale); sy2 = Region.clipScale(sy2, scale); try { return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } catch (InvalidPipeException e) { try { revalidateAll(); return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer); } catch (InvalidPipeException e2) { // Still catching the exception; we are not yet ready to // validate the surfaceData correctly. Fail for now and // try again next time around. return false; } } finally { surfaceData.markDirty(); } }
Example #8
Source File: left_TilesetManager_1.22.java From gumtree-spoon-ast-diff with Apache License 2.0 | 6 votes |
public void loadPreviewImage(Entity entity, Image camo, int tint, BufferedPanel bp) { Image base = mechTileset.imageFor(entity, comp); EntityImage entityImage = new EntityImage(base, tint, camo, bp); Image preview = entityImage.loadPreviewImage(); BackGroundDrawer bgdPreview = new BackGroundDrawer(preview); bp.removeBgDrawers(); bp.addBgDrawer(bgdPreview); MediaTracker tracker = new MediaTracker(comp); tracker.addImage(preview, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { ; } }
Example #9
Source File: GameFrame.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
void setIcon() { String iconName = "cloud32x32.gif"; if (Util.isWindows()) { iconName = "cloud16x16.gif"; } String strURL = "/data/" + iconName; try { MediaTracker tracker = new MediaTracker(frame); URL url = getClass().getResource(strURL); if(url != null) { Image image = frame.getToolkit().getImage(url); tracker.addImage(image, 0); tracker.waitForID(0); frame.setIconImage(image); } else { } } catch (Exception e) { } }
Example #10
Source File: ResourceHolderSwing.java From nullpomino with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Load line clear effect images. */ public static void loadLineClearEffectImages() { String skindir = NullpoMinoSwing.propConfig.getProperty("custom.skin.directory", "res"); if(imgBreak == null) { imgBreak = new Image[BLOCK_BREAK_MAX][BLOCK_BREAK_SEGMENTS]; for(int i = 0; i < BLOCK_BREAK_MAX; i++) { for(int j = 0; j < BLOCK_BREAK_SEGMENTS; j++) { imgBreak[i][j] = loadImage(getURL(skindir + "/graphics/break" + i + "_" + j + ".png")); } } } if(imgPErase == null) { imgPErase = new Image[PERASE_MAX]; for(int i = 0; i < imgPErase.length; i++) { imgPErase[i] = loadImage(getURL(skindir + "/graphics/perase" + i + ".png")); } } }
Example #11
Source File: ImageUtil.java From util with Apache License 2.0 | 6 votes |
/** * 给图片添加文字水印 * @param pressText 水印文字 * @param srcImageFile 源图像地址 * @param destImageFile 目标图像地址 * @param fontName 字体名称 * @param fontStyle 字体样式 * @param color 字体颜色 * @param fontSize 字体大小 * @param x 修正值 * @param y 修正值 * @param alpha 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字 */ public final static void pressText2(String pressText, String srcImageFile,String destImageFile, String fontName, int fontStyle, Color color, int fontSize, int x, int y, float alpha) { try { File img = new File(srcImageFile); Image src = ImageIO.read(img); int width = src.getWidth(null); int height = src.getHeight(null); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.drawImage(src, 0, 0, width, height, null); g.setColor(color); g.setFont(new Font(fontName, fontStyle, fontSize)); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha)); // 在指定坐标绘制水印文字 g.drawString(pressText, (width - (getLength(pressText) * fontSize)) / 2 + x, (height - fontSize) / 2 + y); g.dispose(); ImageIO.write((BufferedImage) image, "JPEG", new File(destImageFile)); } catch (Exception e) { e.printStackTrace(); } }
Example #12
Source File: EndpointArgumentsBuilder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Creates an AttachmentBuilder based on the parameter type * * @param param * runtime Parameter that abstracts the annotated java parameter * @param setter * specifies how the obtained value is set into the argument. Takes * care of Holder arguments. */ public static EndpointArgumentsBuilder createAttachmentBuilder(ParameterImpl param, EndpointValueSetter setter) { Class type = (Class)param.getTypeInfo().type; if (DataHandler.class.isAssignableFrom(type)) { return new DataHandlerBuilder(param, setter); } else if (byte[].class==type) { return new ByteArrayBuilder(param, setter); } else if(Source.class.isAssignableFrom(type)) { return new SourceBuilder(param, setter); } else if(Image.class.isAssignableFrom(type)) { return new ImageBuilder(param, setter); } else if(InputStream.class==type) { return new InputStreamBuilder(param, setter); } else if(isXMLMimeType(param.getBinding().getMimeType())) { return new JAXBBuilder(param, setter); } else if(String.class.isAssignableFrom(type)) { return new StringBuilder(param, setter); } else { throw new UnsupportedOperationException("Unknown Type="+type+" Attachment is not mapped."); } }
Example #13
Source File: LUTCompareTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static Image createTestImage() throws IOException { BufferedImage frame1 = createFrame(new int[] { 0xffff0000, 0xffff0000 }); BufferedImage frame2 = createFrame(new int[] { 0xff0000ff, 0xffff0000 }); ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next(); ImageOutputStream ios = ImageIO.createImageOutputStream(new File("lut_test.gif")); ImageWriteParam param = writer.getDefaultWriteParam(); writer.setOutput(ios); writer.prepareWriteSequence(null); writer.writeToSequence(new IIOImage(frame1, null, null), param); writer.writeToSequence(new IIOImage(frame2, null, null), param); writer.endWriteSequence(); writer.reset(); writer.dispose(); ios.flush(); ios.close(); return Toolkit.getDefaultToolkit().createImage("lut_test.gif"); }
Example #14
Source File: PathGraphics.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) { if (img == null) { return true; } boolean result; int srcWidth = img.getWidth(null); int srcHeight = img.getHeight(null); if (srcWidth < 0 || srcHeight < 0) { result = false; } else { result = drawImage(img, x, y, srcWidth, srcHeight, bgcolor, observer); } return result; }
Example #15
Source File: LUTCompareTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws IOException { Image img = createTestImage(); Toolkit tk = Toolkit.getDefaultToolkit(); LUTCompareTest o = new LUTCompareTest(img); tk.prepareImage(img, -1, -1, o); while(!o.isImageReady()) { synchronized(lock) { try { lock.wait(200); } catch (InterruptedException e) { } } } checkResults(img); }
Example #16
Source File: Util.java From triplea with GNU General Public License v3.0 | 5 votes |
public static void ensureImageLoaded(final Image anImage) { final MediaTracker tracker = new MediaTracker(component); tracker.addImage(anImage, 1); try { tracker.waitForAll(); tracker.removeImage(anImage); } catch (final InterruptedException ignored) { Thread.currentThread().interrupt(); } }
Example #17
Source File: bug8032667_image_diff.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
static BufferedImage getScaledImage(JComponent component) { Image image1x = getImage(component, 1, IMAGE_WIDTH, IMAGE_HEIGHT); final BufferedImage image2x = new BufferedImage( 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB); final Graphics g = image2x.getGraphics(); ((Graphics2D) g).scale(2, 2); g.drawImage(image1x, 0, 0, null); g.dispose(); return image2x; }
Example #18
Source File: XDataTransferer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Translates either a byte array or an input stream which contain * platform-specific image data in the given format into an Image. */ @Override protected Image platformImageBytesToImage( byte[] bytes, long format) throws IOException { String mimeType = null; if (format == PNG_ATOM.getAtom()) { mimeType = "image/png"; } else if (format == JFIF_ATOM.getAtom()) { mimeType = "image/jpeg"; } else { // Check if an image MIME format. try { String nat = getNativeForFormat(format); DataFlavor df = new DataFlavor(nat); String primaryType = df.getPrimaryType(); if ("image".equals(primaryType)) { mimeType = df.getPrimaryType() + "/" + df.getSubType(); } } catch (Exception e) { // Not an image MIME format. } } if (mimeType != null) { return standardImageBytesToImage(bytes, mimeType); } else { String nativeFormat = getNativeForFormat(format); throw new IOException("Translation from " + nativeFormat + " is not supported."); } }
Example #19
Source File: ImageHelper.java From Photato with GNU Affero General Public License v3.0 | 5 votes |
public static BufferedImage resizeImageSmooth(BufferedImage image, int wantedWidth, int wantedHeight) { Image scaledImage = image.getScaledInstance(wantedWidth, wantedHeight, Image.SCALE_SMOOTH); BufferedImage imageBuff = new BufferedImage(wantedWidth, wantedHeight, BufferedImage.TYPE_INT_ARGB); Graphics g = imageBuff.createGraphics(); g.drawImage(scaledImage, 0, 0, null, null); g.dispose(); return imageBuff; }
Example #20
Source File: FileSystemView.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Icon for a file, directory, or folder as it would be displayed in * a system file browser. Example from Windows: the "M:\" directory * displays a CD-ROM icon. * * The default implementation gets information from the ShellFolder class. * * @param f a <code>File</code> object * @return an icon as it would be displayed by a native file chooser * @see JFileChooser#getIcon * @since 1.4 */ public Icon getSystemIcon(File f) { if (f == null) { return null; } ShellFolder sf; try { sf = getShellFolder(f); } catch (FileNotFoundException e) { return null; } Image img = sf.getIcon(false); if (img != null) { return new ImageIcon(img, sf.getFolderType()); } else { return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon"); } }
Example #21
Source File: DrawImage.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public boolean transformImage(SunGraphics2D sg, Image img, AffineTransform atfm, ImageObserver observer) { if (!(img instanceof ToolkitImage)) { transformImage(sg, img, 0, 0, atfm, sg.interpolationType); return true; } else { ToolkitImage sunimg = (ToolkitImage)img; if (!imageReady(sunimg, observer)) { return false; } ImageRepresentation ir = sunimg.getImageRep(); return ir.drawToBufImage(sg, sunimg, atfm, observer); } }
Example #22
Source File: GameboardGUI.java From Spark with Apache License 2.0 | 5 votes |
public void paintComponent(Graphics g) { super.paintComponent(g); final Image backgroundImage = _bg; double scaleX = getWidth() / (double) backgroundImage.getWidth(null); double scaleY = getHeight() / (double) backgroundImage.getHeight(null); AffineTransform xform = AffineTransform .getScaleInstance(scaleX, scaleY); ((Graphics2D) g).drawImage(backgroundImage, xform, this); }
Example #23
Source File: DragSource.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Start a drag, given the <code>DragGestureEvent</code> * that initiated the drag, the initial * <code>Cursor</code> to use, * the <code>Image</code> to drag, * the offset of the <code>Image</code> origin * from the hotspot of the <code>Cursor</code> at * the instant of the trigger, * the <code>Transferable</code> subject data * of the drag, the <code>DragSourceListener</code>, * and the <code>FlavorMap</code>. * <P> * @param trigger the <code>DragGestureEvent</code> that initiated the drag * @param dragCursor the initial {@code Cursor} for this drag operation * or {@code null} for the default cursor handling; * see <a href="DragSourceContext.html#defaultCursor">DragSourceContext</a> * for more details on the cursor handling mechanism during drag and drop * @param dragImage the image to drag or {@code null} * @param imageOffset the offset of the <code>Image</code> origin from the hotspot * of the <code>Cursor</code> at the instant of the trigger * @param transferable the subject data of the drag * @param dsl the <code>DragSourceListener</code> * @param flavorMap the <code>FlavorMap</code> to use, or <code>null</code> * <P> * @throws java.awt.dnd.InvalidDnDOperationException * if the Drag and Drop * system is unable to initiate a drag operation, or if the user * attempts to start a drag while an existing drag operation * is still executing */ public void startDrag(DragGestureEvent trigger, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl, FlavorMap flavorMap) throws InvalidDnDOperationException { SunDragSourceContextPeer.setDragDropInProgress(true); try { if (flavorMap != null) this.flavorMap = flavorMap; DragSourceContextPeer dscp = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger); DragSourceContext dsc = createDragSourceContext(dscp, trigger, dragCursor, dragImage, imageOffset, transferable, dsl ); if (dsc == null) { throw new InvalidDnDOperationException(); } dscp.startDrag(dsc, dsc.getCursor(), dragImage, imageOffset); // may throw } catch (RuntimeException e) { SunDragSourceContextPeer.setDragDropInProgress(false); throw e; } }
Example #24
Source File: CGLSurfaceData.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public CGLVSyncOffScreenSurfaceData(CPlatformView pView, CGLGraphicsConfig gc, int width, int height, Image image, ColorModel cm, int type) { super(pView, gc, width, height, image, cm, type); flipSurface = CGLSurfaceData.createData(pView, image, FLIP_BACKBUFFER); }
Example #25
Source File: DummyPalette.java From netbeans with Apache License 2.0 | 5 votes |
public Image getIcon(int type) { Image icon = null; try { URL url = new URL("nbres:/javax/swing/beaninfo/images/JTabbedPaneColor16.gif"); icon = java.awt.Toolkit.getDefaultToolkit().getImage(url); } catch( MalformedURLException murlE ) { } return icon; }
Example #26
Source File: Win32GraphicsConfig.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Creates a new managed image of the given width and height * that is associated with the target Component. */ public Image createAcceleratedImage(Component target, int width, int height) { ColorModel model = getColorModel(Transparency.OPAQUE); WritableRaster wr = model.createCompatibleWritableRaster(width, height); return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied()); }
Example #27
Source File: Hk2ItemNode.java From netbeans with Apache License 2.0 | 5 votes |
/** * Applies a badge to an open or closed folder icon. * <p/> * @param badge Badge image for folder. * @param opened Use open or closed folder. * @return An image of the badged folder. */ public static Image badgeFolder(Image badge, boolean opened) { Node folderNode = getIconDelegate(); Image folder = opened ? folderNode.getOpenedIcon(BeanInfo.ICON_COLOR_16x16) : folderNode.getIcon(BeanInfo.ICON_COLOR_16x16); return ImageUtilities.mergeImages(folder, badge, 7, 7); }
Example #28
Source File: DitherTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Calculates and returns the image. Halts the calculation and returns * null if the Applet is stopped during the calculation. */ private Image calculateImage() { Thread me = Thread.currentThread(); int width = canvas.getSize().width; int height = canvas.getSize().height; int xvals[] = new int[2]; int yvals[] = new int[2]; int xmethod = XControls.getParams(xvals); int ymethod = YControls.getParams(yvals); int pixels[] = new int[width * height]; int c[] = new int[4]; //temporarily holds R,G,B,A information int index = 0; for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { c[0] = c[1] = c[2] = 0; c[3] = 255; if (xmethod < ymethod) { applyMethod(c, xmethod, i, width, xvals); applyMethod(c, ymethod, j, height, yvals); } else { applyMethod(c, ymethod, j, height, yvals); applyMethod(c, xmethod, i, width, xvals); } pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8) | c[2]); } // Poll once per row to see if we've been told to stop. if (runner != me) { return null; } } return createImage(new MemoryImageSource(width, height, ColorModel.getRGBdefault(), pixels, 0, width)); }
Example #29
Source File: D3DDrawImage.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override protected void renderImageXform(SunGraphics2D sg, Image img, AffineTransform tx, int interpType, int sx1, int sy1, int sx2, int sy2, Color bgColor) { // punt to the MediaLib-based transformImage() in the superclass if: // - bicubic interpolation is specified // - a background color is specified and will be used // - an appropriate TransformBlit primitive could not be found if (interpType != AffineTransformOp.TYPE_BICUBIC) { SurfaceData dstData = sg.surfaceData; SurfaceData srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_GENERIC, sg.imageComp, bgColor); if (srcData != null && !isBgOperation(srcData, bgColor)) { SurfaceType srcType = srcData.getSurfaceType(); SurfaceType dstType = dstData.getSurfaceType(); TransformBlit blit = TransformBlit.getFromCache(srcType, sg.imageComp, dstType); if (blit != null) { blit.Transform(srcData, dstData, sg.composite, sg.getCompClip(), tx, interpType, sx1, sy1, 0, 0, sx2-sx1, sy2-sy1); return; } } } super.renderImageXform(sg, img, tx, interpType, sx1, sy1, sx2, sy2, bgColor); }
Example #30
Source File: ExportARGB.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
static public final int[] extractARGBIntArray( final Image img ) { final int[] pix = new int[img.getWidth(null) * img.getHeight(null)]; PixelGrabber pg = new PixelGrabber( img, 0, 0, img.getWidth(null), img.getHeight(null), pix, 0, img.getWidth(null) ); try { pg.grabPixels(); } catch (InterruptedException ie) {} return pix; }