1

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.

Thanks.

Sandeep Kumar
  • 13,799
  • 21
  • 74
  • 110

2 Answers2

3

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • See also [`RescaleOp`](http://stackoverflow.com/questions/5838842/java-lang-illegalargumentexception-number-of-scaling-constants-does-not-equal-th/5839425#5839425). – trashgod May 25 '11 at 11:01
  • See also [`convertToCompatible()`](http://groups.google.com/group/comp.lang.java.help/msg/bf9c8aa1e05d9f24). – trashgod Dec 24 '11 at 16:56
2

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.

Community
  • 1
  • 1
Rui Vieira
  • 5,253
  • 5
  • 42
  • 55