PDA

View Full Version : copy QPainter content to a QImage



danics
13th January 2013, 06:15
Hi everybody, i want to know how can i copy all content of a QPainter object to a QImage?
i dont have orginal widget reference. before programmers only send QPainter object to another functions.
thanks.

wysota
13th January 2013, 17:27
QPainter doesn't have any "content". If you want to copy content of one paint device to another paint device, the source paint device has to allow it by providing a way to render itself using QPainter (e.g. QWidget::render()).

danics
14th January 2013, 07:42
in qt3 we have bilBlt function for copy one PaintDevice to another, so if i dont know main type of paintdevice how can i copy its content in qt4, however, you mean if i know the main type i can cast it like this?

destpainter.drawImage(0,0, (QImage) (*((QImage*)sourcepainter->device()));

and if i havent paint device type i must using qt3support or another option?

wysota
14th January 2013, 11:13
Maybe you should just explain what you are trying to do?

danics
16th January 2013, 08:55
i have a old program with 170000 lines of code, i must change something in that and port it to qt 4.8, so they have so many function and only send the qpainter object to these functions , i must get a copy of all content of this painters to some images. i haven't the main widget or image reference, now how can i do this?

wysota
16th January 2013, 09:27
It still doesn't explain what you are trying to do. Architecture of Qt3 and Qt4 drawing differs greatly, there is no single magic call you can use.

danics
16th January 2013, 11:40
Ok, I know content of painter's, they have some symbols and i need to extract them, i know the coordinates of symbols and i know the background color too i must extract this symbol without background and load them in another widgets,
it seems i must use bitBlt there is no other choice, am i right?

wysota
16th January 2013, 11:59
So is the source device a QWidget or QImage or what? Do you understand the question I am asking?

danics
16th January 2013, 12:29
you want me to casting paintingdevice?
i m sure its not qwidget its qimage or qpixmap or qbitmap i dont know exactly what is that!

wysota
16th January 2013, 13:08
you want me to casting paintingdevice?
I'm asking you to look into the source code of the application you are maintaining and see what is the source device for the call being made.


i m sure its not qwidget its qimage or qpixmap or qbitmap i dont know exactly what is that!
So check. If it's QImage or QPixmap (or QBitmap which is its subclass) then you can use QImage::copy() or QPixmap::copy().

danics
17th January 2013, 06:16
if i wanna do this i must check so much code, and change so many functions for referencing that object too, if i have only QPainterDevice i cannot do anything?

wysota
17th January 2013, 06:38
if i wanna do this i must check so much code,
Well, I'm sorry. The alternative is to rewrite the whole program from scratch. Use a search tool to help you.