Hi,
I am trying to capture a window image for steaming it over the network.
The code that does the capture looks like:
public BufferedImage paintWindow(final Wnd window)
{
final Rect r = window.getWindowRect();
final WindowDC origDC = WindowDC.getWindowDC(window);
final DDBitmap cap = new DDBitmap(r.getWidth(), r.getHeight());
final DC memDC = DC.createCompatibleDC(origDC);
final Bitmap oldBitmap = memDC.selectObject(cap);
if (Wnd.getForegroundWindow().equals(window))
I assume there is some internal corruption. I am using JNIWrapper 3.8.1
Hi Eilon,
Please try to use the following way to create DDBitmap instance:
final DC screenDC = DC.createDC("DISPLAY", null, null, null);
final DC compatibleDC = DC.createCompatibleDC(screenDC);
Bitmap imageBitmap = new DDBitmap();
Gdi32.getInstance().getFunction("CreateCompatibleBitmap").invoke(
imageBitmap, screenDC, new Int(width), new Int(height));
Bitmap oldBitmap = compatibleDC.selectObject(imageBitmap);
Regards,
Vladimir Ikryanov
Hi Vladimir,
It seems that the com.jniwrapper.win32.gdi.DC class does not have a static "createDC" method,
so I could not test your suggested solution.
Thanks,
Eilon
Hi Eilon,
Please use the following method implementation:
static final Function FUNCTION_CREATE_DC = Gdi32.getInstance().getFunction("CreateDCW");
public static DC createDC(String driver, String device, String output, DevMode initData)
{
DC dc = new DC();
FUNCTION_CREATE_DC.invoke(dc, new Parameter[]{
new Pointer(driver == null ? null : new WideString(driver)),
new Pointer(device == null ? null : new WideString(device)),
new Pointer(output == null ? null : new WideString(output)),
new Pointer(initData == null ? null : initData)
});
return dc;
}
Regards,
Vladimir Ikryanov
Hi Vladimir,
Thanks for your help. I have tried your suggested solution, but it still does not work.
After I create the DDBitmap instance using your example, I proceed with my code
above and eventually call .toImage() method with that DDBitmap instance.
This call seems to hang.
Regards,
Eilon
Hi Eilon,
It looks like ScreenDC is ok only for a screen shot. I think the sample you provided is ok except the LastErrorException. Please make sure that the same algorithm works without issues with the native sample. Maybe the reason of this error in algorithm and it's possible that you get the same results with a native sample.
Regards,
Vladimir Ikryanov
Hi Vladimir,
Aprreciate your help on this.
I have changed my code to use native calls and I do not see the exceptions any more.
Regards,
Eilon