2015-06-18 72 views
43

我创建了一个具有两个窗口的AIR应用程序。第一个是主窗口(spark windowed application),第二个是组件(spark window)。我使用Java通过Flex-Java Bridge Flerry捕获桌面屏幕。跳过窗口被捕获

这里是捕捉这是屏幕的代码: -

HDC hdcWindow = User32.INSTANCE.GetDC(hWnd); 
HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(hdcWindow); 
RECT bounds = new RECT(); 
User32Extra.INSTANCE.GetClientRect(hWnd, bounds); 

int width = bounds.right; 
int height = bounds.bottom ; 
HBITMAP hBitmap = GDI32.INSTANCE.CreateCompatibleBitmap(hdcWindow, width, height); 

HANDLE hOld = GDI32.INSTANCE.SelectObject(hdcMemDC, hBitmap); 
GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, hdcWindow, 0, 0, WinGDIExtra.SRCCOPY); 

我不想被捕获主Flex窗口。它应该跳过(透明)而不被捕获。

这是可能通过更改Flex项目的配置?

如果不能在flex和java中完成,可以在什么平台上完成?

+0

['SetWindowDisplayAffinity'](https://msdn.microsoft.com/en-us/library/windows/desktop/dd375340.aspx)'(HWND,WDA_MONITOR );' – IInspectable

+1

@Iinspectable SetWindowDisplayAffinity不会跳过窗口被捕获。它只会保护窗口不被捕获。我不想用黑色的屏幕代替那个窗口,我想让它的窗口背面显示出来。 – Vishnu

+0

当你的问题甚至不能远程指定所需的行为时,任何人都应该知道你想要什么?在你的评论中要求的是 - 一般来说 - 不可能的。 – IInspectable

回答

1

如果我正确理解你的问题。

您可以使用内置的Flex/AS3功能把整个应用程序或特定组件的截图,然后转换成字节组和包括PNGEncoder(或JPGEncoder如果你喜欢),比它保存...

这里的一个例子:

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.graphics.codec.PNGEncoder; 

      private function takeSnapshot(comp:DisplayObject):void { 
       var bitmapData:BitmapData = new BitmapData(comp.width,comp.height,false,0x00000000); 
       bitmapData.draw(comp, new Matrix()); 

       var fileStream:FileStream = new FileStream(); 
       fileStream.open(File.desktopDirectory.resolvePath("screenshot.png"), FileMode.UPDATE); 
       fileStream.writeBytes(new PNGEncoder().encode(bitmapData)); 
      } 
     ]]> 
    </fx:Script>  
    <s:BorderContainer width="100%" height="100%" backgroundColor="#ff00ff"> 
     <s:Label text="this text and box should be saved"/> 
     <s:BorderContainer width="25%" height="25%" backgroundColor="#ffff00" horizontalCenter="0" 
          id="extended" 
          verticalCenter="0"> 
      <s:Label text="this text and box should be saved" width="100%" maxDisplayedLines="5"/> 
     </s:BorderContainer> 
    </s:BorderContainer>  
    <s:Button bottom="0" left="0" label="screen" click="takeSnapshot(extended)"/> 
</s:WindowedApplication> 

编辑:

正如我想我误解请求..

我能想到的唯一方法是:

  1. 最小化应用(this.minimize();)或α设置为0(this.alpha=0)。
  2. 截取屏幕截图
  3. 最大化应用程序(this.maximize();)或将alpha设置为1(this.alpha=0)。
+0

对不起。我想捕获桌面屏幕,而不是Flex应用程序。 – Vishnu

+0

哦......该死的......我误解了......答案已更新。 – Marcx

+0

这会在屏幕上产生闪烁效果。 Bitblt需要200毫秒才能捕捉屏幕。我已经尝试过了。你不能在java中使用flex应用程序的'this.minimize'或'this.alpha' – Vishnu

0

我能想到的一个解决方案是,您可以将“不想要的”窗口移出捕获状态。 (在0,0坐标下面),用这样的代码。

public void foo(){ 
this.xCoord = -this.xCoord; 
this.yCoord = -this.yCoord; 
} 
//Im not sure about the exact syntax but you should get the idea. 

和比

foo(); 
capture(); 
foo();