uchar* QImage::bits() returned '\0'...(nullptr)
-
Hi to all guys,
Today, I'm trying to represent QImage as AVFrame(ffmpeg API).
// localImage is RGB32 QImage that fetching in func QImage *img = new QImage(localImage); if (!img->isNull()) { uchar* bits = img->bits(); }
But bits() func always return null, my uchar* pointer in debug always 0 or '\0'... What's wrong?
Thanks so much for your attention!
-
Hi
What is localImage ? ( Type ) -
@mrjj Hi, thanks for your reply :) Format_RGB32
-
@shtomik
So its from
QImage QOpenGLWidget::grabFramebuffer() ?
Did you check what
http://doc.qt.io/qt-5/qimage.html#isNull
says ?
Also, do you do something like
https://stackoverflow.com/questions/13088749/efficient-conversion-of-avframe-to-qimage -
So its from
QImage QOpenGLWidget::grabFramebuffer() ?Yes.
Did you check what
http://doc.qt.io/qt-5/qimage.html#isNull
says ?Yea, what's wrong? In debug mode I saw that image is 1280x720 and with data...
Also, do you do something like
https://stackoverflow.com/questions/13088749/efficient-conversion-of-avframe-to-qimageI read it, but I want to "convert" from QImage to AVFrame, not to QImage... I had a code for "converting" without data copy, but QImage::bits() func returned not correct pointer? If need to list code for converting, I can paste it, but is it correct way to think that my trouble really in bits() func? Thanks!
-
@shtomik
Hi
ok so localImage is valid ?
Normally its due to invalid image it returns null.
But if in Format_RGB32 it should work.
localImage bits() also returns null ? -
ok so localImage is valid ?
localImage bits() also returns null ?localImage and img I can to QImage::save(QStrings path ...), and it's work... So I think valid... 1 minute, please, I check it in debug. Thanks again ;)
-
@mrjj
Yes, is valid, I can save pic and not null... All is good, but what's wrong?(Now I'm using:
QImage *img = new QImage(ui->oGLArea->grabFramebuffer());
without localImage...
-
So
After copying QImage to QImage, bits() fail ?
QImage::QImage(const QImage &image)
makes a shallow copy so i wonder if something goes out of scope ?
If you do
QImage img = ui->oGLArea->grabFramebuffer();
is bits() still NULL ?
Im wondering of the implicit sharing is doing something. -
@mrjj
I'm trying QImage::copy() too, but it's fail...If you do
QImage img = ui->oGLArea->grabFramebuffer();
is bits() still NULL ?Yes.
-
@shtomik
Hmm. that is really odd if u can save them as working files.
Im out of guesses.
Give it some hours , others will come online and might have a good idea. -
@mrjj
thank you so much for your time and replies! I'm here... :) -
what does
qDebug() << QByteArray(reinterpret_cast<const char*>(img->constBits()),img->bytesPerLine()).size();
print out (if it doesn't crash)? -
Are you sure its null ? By that I mean, what happens if you test
if ( bits == nullptr ) { } else { qDebug () << *bits << *(bits + 1) << *(bits + 2) }
I ask because your description of whats shown in the debuggers sounds like the
debugger is looking at the first part of the pixel, which could be 0. -
@VRonin
It doesn't crash o_O
5120 - output -
@mranger90
You are right! If first pixel not BLACK, debuger shows buffer of bits, but if first char - 0, empty buffer... -
Thank you guys... I found a couple of mistakes in my code, but the main mistake was in trust to the debugger, sometimes it was 0x0 or 0 or '\0' value for pointer to uchar that was 0.