BufferedImage颜色变化 [英] BufferedImage colour change

查看:148
本文介绍了BufferedImage颜色变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个应用程序,它捕获屏幕截图并从捕获的图像中创建视频。但问题是,当生成视频时,生成的视频中的颜色非常粉红。我想这是因为我正在使用BufferedImage.TYPE_3BYTE_BGR类型操纵捕获的图像来显示光标。有人可以告诉我如何解决这个问题,我希望视频的颜色与屏幕的实际颜色相同。

I have working on an application which captures screen shots and create video from captured images. But the problem is that when video is generated, colours in generated video is very pinkish. I think this is because I am manipulating captured images to show cursor using BufferedImage.TYPE_3BYTE_BGR type. Could someone tell me how to resolve this issue, I want to have the colour of video same as actual colour of screen.

为了捕获屏幕图像,我的工作如下:

For capturing screen image I am doing as follows:

Robot robot = new Robot();
Rectangle captureSize = new Rectangle(screenBounds);
return robot.createScreenCapture(captureSize);

我操作图像的方式如下:

For manipulating images I am doing as follows:

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;

请告诉我如何在屏幕上获取与实际颜色相同颜色的图像。

please tell me how to get the images with colour same as actual colour on screen.

谢谢。

推荐答案

使用 BufferedImage.TYPE_INT_ARGB BufferedImage.TYPE_INT_RGB ,如此示例的。如果您需要更改颜色,可以使用 LookupOp ,带有四个组件的LookupTable,可根据 BufferedImage.TYPE_3BYTE_BGR :何时数据如果将非不透明的alpha存储在此类型的图像中,则必须将颜色数据调整为非预乘形式并丢弃alpha。示例可以在 使用Java 2D LookupOp 过滤类来处理图像 使用Java 2D进行图像处理

Use BufferedImage.TYPE_INT_ARGB or BufferedImage.TYPE_INT_RGB, as shown in this example. If you need to change the colors, you can use a LookupOp with a four-component LookupTable that adjusts the alpha component as required for BufferedImage.TYPE_3BYTE_BGR: "When data with non-opaque alpha is stored in an image of this type, the color data must be adjusted to a non-premultiplied form and the alpha discarded." Examples may be found in Using the Java 2D LookupOp Filter Class to Process Images and Image processing with Java 2D.

这篇关于BufferedImage颜色变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆