Vis*_*hnu 43 java apache-flex air winapi jna
我创建了一个AIR应用程序,它有两个窗口.第一个是主窗口(spark Windowed Application),第二个是组件(spark窗口).我正在使用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);
Run Code Online (Sandbox Code Playgroud)
我不希望捕获主要的flex窗口.它应该被跳过(透明)被捕获.
这可以通过改变flex项目的配置来实现吗?
如果无法在flex和java中完成,可以在什么平台上完成?
如果我正确理解你的问题。
您可以使用内置的 Flex/as3 函数截取整个应用程序或特定组件的屏幕截图,然后转换为 bytearray 和 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>
Run Code Online (Sandbox Code Playgroud)
编辑:
因为我以为我误解了这个要求..
我能想到的唯一方法是:
this.minimize();
) 或将 alpha 设置为 0 ( this.alpha=0
)。this.maximize();
) 或将 alpha 设置为 1 ( this.alpha=0
)。