PDA

View Full Version : Take a screenshot and convert it to PNG but FAST !



fitzy
3rd November 2009, 13:22
Hi there!

My program takes screenshots using QPixmap::grabWindow(); then I convert it to PNG.

However the convertion is very slow (about 1 sec) and I need it to be much faster than that.

Any idea :confused:


In fact, I think that if I can capture the screen directly as a PNG, it would be great but I don't know how to do that.

harish.surana
3rd November 2009, 16:08
have you checked screenshot example present in Qt Source code Qt/4.x.x/examples/desktop/screenshot

fitzy
3rd November 2009, 16:34
Actually I know how to take a screenshot.

I now want to convert it to PNG quickly.

wysota
3rd November 2009, 17:23
Convert it from what?

harish.surana
3rd November 2009, 17:24
from pixmap to png

QString format = "png";
Pixmap.save(fileName, format.toAscii());

fitzy
3rd November 2009, 18:59
from pixmap to png

QString format = "png";
Pixmap.save(fileName, format.toAscii());

Yes from Pixmap to PNG, but what I said is that this method is to slow ! (pixmap.save())

Is there any other way to take a screenshot and convert it to PNG QUICKLY ?

wysota
3rd November 2009, 19:33
Is there any other way to take a screenshot and convert it to PNG QUICKLY ?

Yes, switch to Windows, QPixmap::toImage() is a no-op there. BTW. You don't convert it from pixmap to png, you convert it from pixmap to image and then save it as png.

fitzy
3rd November 2009, 21:02
Yes, switch to Windows, QPixmap::toImage() is a no-op there. BTW. You don't convert it from pixmap to png, you convert it from pixmap to image and then save it as png.



You're right, but which function should I use ?

wysota
3rd November 2009, 23:03
You're right, but which function should I use ?

I don't understand your question. What function do you mean? Are you sure you understood my last reply?

fitzy
4th November 2009, 00:25
I'm sorry, here is what I meant :


You don't convert it from pixmap to png, you convert it from pixmap to image and then save it as png.
my answer :

You're right.

---


Yes, switch to Windows, QPixmap::toImage() is a no-op there. BTW.

You are talking about win32, right ? If you do, which specific function should I use ?

caduel
4th November 2009, 07:28
if I understood that correctly:
use QPixmap::toImage(). It just happens to be fast on windows because there is nothing (or not much) to do internally. For you as a Qt user you always do grabWindow(), then QPixmap::toImage(), then QImage::save().

(This sequence just happens to be faster on the windows platform.)

wysota
4th November 2009, 08:20
if I understood that correctly:
use QPixmap::toImage(). It just happens to be fast on windows because there is nothing (or not much) to do internally. For you as a Qt user you always do grabWindow(), then QPixmap::toImage(), then QImage::save().

That's exactly what I meant - QPixmap::toImage() is a no-op on Windows. It's probably a no-op if you use the raster painting engine on X11 as well but I'm not sure of that.