[Qt-interest] Convert from a QPixmap into a QByteArray, and back
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Wed May 19 02:05:18 CEST 2010
This this…..
Scott
int main( int argc, char ** argv )
{
QApplication appl( argc, argv );
QPixmap screen = QPixmap::grabWindow( QApplication::desktop()->winId(), 0, 0, 500, 500 );
QLabel label;
label.setPixmap( screen );
label.show();
screen.save( "7777.png" );
QPixmap screenLoaded( "7777.png" );
QLabel label2;
label2.setPixmap( screenLoaded );
label2.show();
QByteArray bytes;
QDataStream out( &bytes, QIODevice::WriteOnly );
out << screen;
QDataStream in( &bytes, QIODevice::ReadOnly );
QPixmap screenStream;
in >> screenStream;
QLabel label3;
label3.setPixmap( screenStream );
label3.show();
return appl.exec();
}
Works for me…
Scott
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Gabriele Kahlout
Sent: Tuesday, May 18, 2010 2:54 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] Convert from a QPixmap into a QByteArray, and back
Hello,
In the process of debugging I've found myself unable to assert the following code:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
const QPixmap screen = QPixmap::grabWindow(QApplication::desktop()->winId());
QByteArray *bytes = new QByteArray();
QDataStream out(bytes, QIODevice::WriteOnly);
out << screen;
QPixmap* screen1 = new QPixmap();
screen1->loadFromData(bytes->data());
std::cout << screen1->save("7777.png", "PNG") << endl;
std::cout << screen.save("6666.png", "PNG") << endl;
return a.exec();
}
All I'm doing is trying to convert from a QPixmap into a QByteArray, and back. Although the code is mostly verbatim from QPixmap and QDataStream, it doens't work. Indeed screen1 fails to save into 7777.png.
Your help, fixing this code, is greatly appreciated.
--
Regards,
K. Gabriele
--- unchanged since 25/1/10 ---
P.S. Unless a notification (LON), please reply either with an answer OR with " ACK" appended to this subject within 48 hours. Otherwise, I might resend.
In(LON, this) ∨ In(48h, TimeNow) ∨ ∃x. In(x, MyInbox) ∧ IsAnswerTo(x, this) ∨ (In(subject(this), subject(x)) ∧ In(ACK, subject(x)) ∧ ¬IsAnswerTo(x,this)) ⇒ ¬IResend(this).
Also note that correspondence may be received only from specified a priori senders, or if the subject of this email ends with a code, eg. -LICHT01X, then also from senders whose reply contains it.
∀x. In(x, MyInbox) ⇒ In(senderAddress(x), MySafeSenderList) ∨ (∃y. In(y, subject(this) ) ∧ In(y,x) ∧ isCodeLike(y, -LICHT01X) ).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100518/8eb496c0/attachment.html
More information about the Qt-interest-old
mailing list