开发者

BufferedImage colour change

开发者 https://www.devze.com 2023-03-08 11:24 出处:网络
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

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 sc开发者_如何学运维reen 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.

Thanks.


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.


See the the "pinkish" explanation here

Basically the image is saved as a ARGB and most viewers interpret it as a CMYK. Alpha is preserved when opening it back in Java, though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号