我正在开发一个应用程序,它可以捕获屏幕截图并根据捕获的图像创建视频。但问题是,当生成视频时,生成的视频中的颜色非常粉红色。我认为这是因为我正在使用 BufferedImage.TYPE_3BYTE_BGR 类型处理捕获的图像以显示光标。谁能告诉我如何解决这个问题,我想让视频的颜色与屏幕的实际颜色相同。
为了捕获屏幕图像,我正在执行以下操作:
Robot robot = new Robot();
Rectangle captureSize = new Rectangle(screenBounds);
return robot.createScreenCapture(captureSize);
我按如下方式处理图像:
image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
if (true) {
int x = MouseInfo.getPointerInfo().getLocation().x - 25;
int y = MouseInfo.getPointerInfo().getLocation().y - 37;
Graphics2D graphics2D = sourceImage.createGraphics();`enter code here`
graphics2D.drawImage(SimpleWebBrowserExample.m_MouseIcon, x, y, 48, 48, null);
}
image.getGraphics().drawImage(sourceImage, 0, 0, null);
return image;
请告诉我如何使图像的颜色与屏幕上的实际颜色相同。
谢谢。
最佳答案
使用BufferedImage.TYPE_INT_ARGB
或 BufferedImage.TYPE_INT_RGB
,如图所示 example .如果需要更改颜色,可以使用 LookupOp
具有四分量的 LookupTable,可根据 BufferedImage.TYPE_3BYTE_BGR
的需要调整 alpha 分量:“当具有非不透明 alpha 的数据存储在这种类型的图像中时,必须将颜色数据调整为非预乘形式并丢弃 alpha。”示例可在 Using the Java 2D LookupOp
Filter Class to Process Images 中找到和 Image processing with Java 2D .
关于java - BufferedImage 颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6122964/