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();
}
}
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);
}
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());
}
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);
}
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");
}
}
Aggregations