Java Code Examples for java.awt.Image

The following examples show how to use java.awt.Image. These examples are extracted from open source projects.
Example 1
Project: openjdk-8   File: FileSystemView.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 2
Project: openjdk-8   File: WTrayIconPeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 3
Project: jdk8u-jdk   File: TranslucentWindowPainter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 4
Project: jdk8u-jdk   File: LUTCompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 5
Project: netbeans   File: DOMNodeAnnotator.java    License: Apache License 2.0 6 votes vote down vote up
@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 6
Project: openjdk-jdk9   File: LUTCompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 7
Project: openjdk-8-source   File: TranslucentWindowPainter.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 8
Project: openjdk-8   File: SunGraphics2D.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 9
Project: gumtree-spoon-ast-diff   File: left_TilesetManager_1.22.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Project: knopflerfish.org   File: GameFrame.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 11
Project: nullpomino   File: ResourceHolderSwing.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 12
Project: util   File: ImageUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 给图片添加文字水印
 * @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 13
Project: openjdk-jdk8u-backup   File: EndpointArgumentsBuilder.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 14
Project: openjdk-jdk9   File: LUTCompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 15
Project: jdk8u_jdk   File: PathGraphics.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 16
Project: openjdk-jdk8u-backup   File: LUTCompareTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 17
Project: triplea   File: Util.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 18
Project: jdk8u-jdk   File: bug8032667_image_diff.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 19
Project: openjdk-jdk9   File: XDataTransferer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 20
Project: Photato   File: ImageHelper.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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 21
Project: jdk8u-jdk   File: DrawImage.java    License: GNU General Public License v2.0 5 votes vote down vote up
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
Project: Spark   File: GameboardGUI.java    License: Apache License 2.0 5 votes vote down vote up
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
Project: hottub   File: DragSource.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Project: TencentKona-8   File: CGLSurfaceData.java    License: GNU General Public License v2.0 5 votes vote down vote up
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
Project: netbeans   File: DummyPalette.java    License: Apache License 2.0 5 votes vote down vote up
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
Project: TencentKona-8   File: Win32GraphicsConfig.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Project: netbeans   File: Hk2ItemNode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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
Project: jdk8u-jdk   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
Project: jdk8u60   File: D3DDrawImage.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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
Project: TrakEM2   File: ExportARGB.java    License: GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 31
Project: jdk8u-jdk   File: jpeg.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
    Class<?>[] cls = classes;
    for (int i = 0; i < cls.length; i++) {
        if (cls[i].isAssignableFrom(URLImageSource.class)) {
            return new URLImageSource(urlc);
        }
        if (cls[i].isAssignableFrom(Image.class)) {
            Toolkit tk = Toolkit.getDefaultToolkit();
            return tk.createImage(new URLImageSource(urlc));
        }
    }
    return null;
}
 
Example 32
Project: openjdk-jdk8u   File: TranslucentWindowPainter.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static final Image clearImage(Image bb) {
    Graphics2D g = (Graphics2D)bb.getGraphics();
    int w = bb.getWidth(null);
    int h = bb.getHeight(null);

    g.setComposite(AlphaComposite.Src);
    g.setColor(new Color(0, 0, 0, 0));
    g.fillRect(0, 0, w, h);

    return bb;
}
 
Example 33
Project: hottub   File: PeekGraphics.java    License: GNU General Public License v2.0 5 votes vote down vote up
synchronized public boolean imageUpdate(Image image, int flags,
                                        int x, int y, int w, int h) {

    boolean dontCallMeAgain = (flags & (HEIGHT | ABORT | ERROR)) != 0;
    badImage = (flags & (ABORT | ERROR)) != 0;

    return dontCallMeAgain;
}
 
Example 34
Project: itext2   File: Barcode128.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Creates a <CODE>java.awt.Image</CODE>. This image only
 * contains the bars without any text.
 * @param foreground the color of the bars
 * @param background the color of the background
 * @return the image
 */    
public java.awt.Image createAwtImage(Color foreground, Color background) {
    int f = foreground.getRGB();
    int g = background.getRGB();
    Canvas canvas = new Canvas();
    String bCode;
    if (codeType == CODE128_RAW) {
        int idx = code.indexOf('\uffff');
        if (idx >= 0)
            bCode = code.substring(0, idx);
        else
            bCode = code;
    }
    else {
        bCode = getRawText(code, codeType == CODE128_UCC);
    }
    int len = bCode.length();
    int fullWidth = (len + 2) * 11 + 2;
    byte bars[] = getBarsCode128Raw(bCode);
    
    boolean print = true;
    int ptr = 0;
    int height = (int)barHeight;
    int pix[] = new int[fullWidth * height];
    for (int k = 0; k < bars.length; ++k) {
        int w = bars[k];
        int c = g;
        if (print)
            c = f;
        print = !print;
        for (int j = 0; j < w; ++j)
            pix[ptr++] = c;
    }
    for (int k = fullWidth; k < pix.length; k += fullWidth) {
        System.arraycopy(pix, 0, pix, k, fullWidth); 
    }
    Image img = canvas.createImage(new MemoryImageSource(fullWidth, height, pix, 0, fullWidth));
    
    return img;
}
 
Example 35
Project: jdk8u-jdk   File: CGLGraphicsConfig.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
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 36
Project: dragonwell8_jdk   File: CGLSurfaceData.java    License: GNU General Public License v2.0 5 votes vote down vote up
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 37
Project: PeerWasp   File: JSystemTray.java    License: MIT License 5 votes vote down vote up
private TrayIcon create(Image image) throws IOException {
	TrayIcon trayIcon = new java.awt.TrayIcon(image);
	trayIcon.setImageAutoSize(true);
	trayIcon.setToolTip(tooltip);
	trayIcon.setPopupMenu(createMenu(false));
	return trayIcon;
}
 
Example 38
Project: WorldGrower   File: BackgroundPainter.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Image createCombinedImage(Image sourceImage, TerrainType backgroundTerrainType, TerrainType transitionTerrainType, ImageIds imageId) {
	BufferedImage bimage = new BufferedImage(sourceImage.getWidth(null), sourceImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);

	Graphics2D bGr = bimage.createGraphics();
	bGr.drawImage(getBackgroundImage(transitionTerrainType), 0, 0, null);
	bGr.drawImage(createTransition(sourceImage, backgroundTerrainType, transitionTerrainType, imageId), 0, 0, null);
	bGr.dispose();
	return bimage;
}
 
Example 39
Project: openjdk-8-source   File: DitherTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 40
Project: openjdk-jdk9   File: WDataTransferer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 == CF_PNG) {
        mimeType = "image/png";
    } else if (format == CF_JFIF) {
        mimeType = "image/jpeg";
    }
    if (mimeType != null) {
        return standardImageBytesToImage(bytes, mimeType);
    }

    int[] imageData = platformImageBytesToImageData(bytes, format);
    if (imageData == null) {
        throw new IOException("data translation failed");
    }

    int len = imageData.length - 2;
    int width = imageData[len];
    int height = imageData[len + 1];

    DataBufferInt buffer = new DataBufferInt(imageData, len);
    WritableRaster raster = Raster.createPackedRaster(buffer, width,
            height, width,
            bandmasks, null);

    return new BufferedImage(directColorModel, raster, false, null);
}