Pregunta

I use this code to generate screenshots in java. I use the method about 5-10 times per second, calculate some values out of the screenshot and send them away, so I do not store the screenshots. This works fine for some time (10-30 minutes), but then the method returns null, because this line ok = GDI.GetDIBits(blitDC, outputBitmap, 0, raster.getHeight(), pixels, bi, 0); in the bufferedImageFromBitmap-method returns false.

If I invoke the method again, it returns null again.
I've tried to use java.awt.Robot if the JNA-method fails, but then a OutOfMemoryException is thrown (I've tried System.gc() and giving the program more memory, but the Exception is still thrown.), but in the taskmanager I don't see that the program uses more memory.

Do you have an idea what I could do (fix/workaround/...)?

¿Fue útil?

Solución

The problem is solved thanks to technomage:
If I call windowDC = GDI.GetDC(USER.GetDesktopWindow()); only once and then reuse windowDC, it won't stop working.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top