Search in sources :

Example 16 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project wechat by dllwh.

the class OperateImageHelper method gray.

/**
 * 彩色转为黑白
 *
 * @param srcImageFile
 *            源图像地址
 * @param destImageFile
 *            目标图像地址
 */
public static final void gray(String srcImageFile, String destImageFile) {
    try {
        BufferedImage src = ImageIO.read(new File(srcImageFile));
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        ColorConvertOp op = new ColorConvertOp(cs, null);
        src = op.filter(src, null);
        ImageIO.write(src, "jpg", new File(destImageFile));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) ColorSpace(java.awt.color.ColorSpace) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 17 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project nationgen by elmokki.

the class Drawing method greyscale.

public static BufferedImage greyscale(BufferedImage image, int units) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    ColorConvertOp op = new ColorConvertOp(cs, null);
    BufferedImage newimage = op.filter(image, null);
    BufferedImage n = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics g = n.getGraphics();
    g.drawImage(newimage, 0, 0, null);
    for (int x = 0; x < image.getWidth(); x++) for (int y = 0; y < image.getHeight(); y++) {
        int clr = image.getRGB(x, y);
        int red = (clr & 0x00ff0000) >> 16;
        int green = (clr & 0x0000ff00) >> 8;
        int blue = clr & 0x000000ff;
        if (red > 247 && blue > 247 && green == 0) {
            n.setRGB(x, y, clr);
        }
    }
    return darken(n, units);
}
Also used : Graphics(java.awt.Graphics) ColorConvertOp(java.awt.image.ColorConvertOp) ColorSpace(java.awt.color.ColorSpace) BufferedImage(java.awt.image.BufferedImage)

Example 18 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project jmonkeyengine by jMonkeyEngine.

the class ImageUtils method convertToGrayscaleTexture.

/**
     * This method converts the given texture into black and whit (grayscale) texture.
     * 
     * @param source
     *            the source texture
     * @return grayscale texture
     */
public static Image convertToGrayscaleTexture(Image source) {
    BufferedImage sourceImage = ImageToAwt.convert(source, false, false, 0);
    ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    op.filter(sourceImage, sourceImage);
    return ImageUtils.toJmeImage(sourceImage, source.getFormat());
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) BufferedImage(java.awt.image.BufferedImage)

Example 19 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project intellij-plugins by JetBrains.

the class SwingUtils method getGreyIcon.

@NotNull
public static Icon getGreyIcon(@NotNull Icon icon) {
    ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    BufferedImage originalImage = convertIconToBufferedImage(icon);
    BufferedImage greyImage = op.filter(originalImage, null);
    return new ImageIcon(greyImage);
}
Also used : ColorConvertOp(java.awt.image.ColorConvertOp) BufferedImage(java.awt.image.BufferedImage) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with ColorConvertOp

use of java.awt.image.ColorConvertOp in project intellij-community by JetBrains.

the class MacColorPipette method captureScreen.

@Nullable
static BufferedImage captureScreen(@Nullable Window belowWindow, @NotNull Rectangle rect) {
    ID pool = Foundation.invoke("NSAutoreleasePool", "new");
    try {
        ID windowId = belowWindow != null ? MacUtil.findWindowFromJavaWindow(belowWindow) : null;
        Foundation.NSRect nsRect = new Foundation.NSRect(rect.x, rect.y, rect.width, rect.height);
        ID cgWindowId = windowId != null ? Foundation.invoke(windowId, "windowNumber") : ID.NIL;
        int windowListOptions = cgWindowId != null ? FoundationLibrary.kCGWindowListOptionOnScreenBelowWindow : FoundationLibrary.kCGWindowListOptionAll;
        int windowImageOptions = FoundationLibrary.kCGWindowImageNominalResolution;
        ID cgImageRef = Foundation.cgWindowListCreateImage(nsRect, windowListOptions, cgWindowId, windowImageOptions);
        ID bitmapRep = Foundation.invoke(Foundation.invoke("NSBitmapImageRep", "alloc"), "initWithCGImage:", cgImageRef);
        ID nsImage = Foundation.invoke(Foundation.invoke("NSImage", "alloc"), "init");
        Foundation.invoke(nsImage, "addRepresentation:", bitmapRep);
        ID data = Foundation.invoke(nsImage, "TIFFRepresentation");
        ID bytes = Foundation.invoke(data, "bytes");
        ID length = Foundation.invoke(data, "length");
        ByteBuffer byteBuffer = Native.getDirectByteBuffer(bytes.longValue(), length.longValue());
        Foundation.invoke(nsImage, "release");
        byte[] b = new byte[byteBuffer.remaining()];
        byteBuffer.get(b);
        BufferedImage result = ImageIO.read(new ByteArrayInputStream(b));
        if (result != null) {
            ColorSpace ics = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            ColorConvertOp cco = new ColorConvertOp(ics, null);
            return cco.filter(result, null);
        }
        return null;
    } catch (Throwable t) {
        LOG.error(t);
        return null;
    } finally {
        Foundation.invoke(pool, "release");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ColorConvertOp(java.awt.image.ColorConvertOp) ColorSpace(java.awt.color.ColorSpace) Foundation(com.intellij.ui.mac.foundation.Foundation) ID(com.intellij.ui.mac.foundation.ID) ByteBuffer(java.nio.ByteBuffer) BufferedImage(java.awt.image.BufferedImage) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ColorConvertOp (java.awt.image.ColorConvertOp)39 BufferedImage (java.awt.image.BufferedImage)37 ColorModel (java.awt.image.ColorModel)12 ColorSpace (java.awt.color.ColorSpace)10 IndexColorModel (java.awt.image.IndexColorModel)10 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)5 Point (java.awt.Point)4 WritableRaster (java.awt.image.WritableRaster)3 IIOException (javax.imageio.IIOException)3 Color (java.awt.Color)2 Graphics (java.awt.Graphics)2 ComponentColorModel (java.awt.image.ComponentColorModel)2 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)2 Test (org.junit.jupiter.api.Test)2 ImageProcessingException (com.drew.imaging.ImageProcessingException)1 Metadata (com.drew.metadata.Metadata)1 Foundation (com.intellij.ui.mac.foundation.Foundation)1 ID (com.intellij.ui.mac.foundation.ID)1 Vector3f (com.jme3.math.Vector3f)1 ImageFeature (de.neotos.imageanalyzer.ImageFeature)1