2011-05-25 149 views
1

我有一個應用程序捕獲屏幕截圖並從捕獲的圖像創建視頻。但問題是,當視頻生成時,生成的視頻中的顏色非常粉紅。我認爲這是因爲我正在使用BufferedImage.TYPE_3BYTE_BGR類型操縱捕獲的圖像以顯示遊標。有人能告訴我如何解決這個問題,我想讓視頻的顏色與屏幕的實際顏色相同。BufferedImage顏色變化

用於捕捉我做的畫面如下:

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; 

請告訴我如何與顏色相同,實際得到的圖像屏幕上的顏色。

謝謝。

回答

3

使用BufferedImage.TYPE_INT_ARGBBufferedImage.TYPE_INT_RGB,如此example所示。如果需要更改顏色,可以使用LookupOp以及一個四部件LookupTable,該部件根據BufferedImage.TYPE_3BYTE_BGR的要求調整alpha分量:「當具有非透明Alpha的數據存儲在此類型的圖像中時,顏色數據必須將其調整爲非預乘形式,並丟棄α。「例子可以在Using the Java 2D LookupOp Filter Class to Process ImagesImage processing with Java 2D中找到。

+0

另請參閱['RescaleOp'](http://stackoverflow.com/questions/5838842/java-lang-illegalargumentexception-number-of-scaling-constants-does-not-equal-th/5839425#5839425)。 – trashgod 2011-05-25 11:01:58

+0

請參閱['convertToCompatible()'](http://groups.google.com/group/comp.lang.java.help/msg/bf9c8aa1e05d9f24)。 – trashgod 2011-12-24 16:56:58

2

看到的「粉紅色」的解釋here

基本上將圖像保存爲ARGB和大多數觀衆把它解釋爲CMYK。不過,在Java中打開Alpha時會保留Alpha。