c++ - Convert byte array to picture -
hello try convert byte array image each time null image, me please ?
qimage image("p.jpg"); qdebug()<<image; qimage image2; qbytearray paquet2; qdatastream out2(&paquet2, qiodevice::writeonly); out2 << image; qdebug()<<image2.fromdata(paquet2,"jpg");
qdebug 1 result: qimage(qsize(500,500))
qdebug 2 result: qimage(qsize(0,0))
fromdata()
static method.
try image2.loadfromdata(paquet2)
or qimage::fromdata(paquet2)
instead.
i noticed strange, code works expected:
qimage img("..."); qbytearray data; qbuffer buff(&data); qdatastream out(&buff); out << img; qdebug() << qimage::fromdata(data);
but gives warning iodevice
not being open.
if manually buff.open()
, fromdata()
produces null image again.
without explicitly opening, openmode()
automatically set unbuffered | writeonly
, works, if open()
explicitly unbuffered | writeonly
doesn't work. go figure...
Comments
Post a Comment