Back when I was using char table to modify QImage on QT 4, each pixel was stored using 4 unsigned chars (Red, Green, Blue, transparency). I imagine it's still stored that way, so 10th pixel was represented by ptr, ptr, ptr and ptr.
You'd need to modify Qt code to print some message when detach happens. But you will get a lot of these messages, as implicit sharing is used everywhere (all container classes, plus many more general Qt classes). You can use clazy tool to get some hints of inefficient use of shared classes, I think.
One good rule of thumb is - if you pass QImage (or any other implicitly shared class) into a function, always use const reference:
void someMethod(const QImage &image);
Also, be careful when using ranged for loop, it can detach if container is not const.
qDebug can't show the base64 string for some reason because
std::cout << imgBase64.toStdString();
prints the correct base64 string. I did try serval version of code before i posted here. If i read the png from file and get a base64 from it, the same happens without the buffer. qDebug won't print out the base64 string.
ba = file2.readAll().toBase64();
qDebug() << "base64 from png: " << ba.data(); // nothing
std::cout << ba.data(); // works
QPainter can draw a QImage. So you can for example create a new Widget, subclass for QLabel for example if you want and reimplement paintEvent. Like this you work all the time with your QImage without creating another one.
And better you can only update the region that changed, no need to refresh everything. I did not try it but it should work.
slightly more refined solution using the fact that QImage uses "a matrix" internally
outStream << image.height()<< image.width(); /* You need this to recover the image size, if not needed remove*/
QImage testImage= image.convertToFormat(QImage::Format_Mono,Qt::MonoOnly); /* 1 bit= 1 pixel*/
testImage.invertPixels(); /* black is 1 and white is 0 normally, you need the opposite so invert*/
const int bytesInWidth =
+ (testImage.width()%8>0 ? 1:0);
/*This is image.width()/8 rounded up */
@helenebro QImage::Format_Mono or QImage::Format_MonoLSB will both do the job. You can then read/write 0/1 with QImage::pixel() / QImage::setPixel(). For faster access to the pixel data, if that is needed, you should use the direct accessors with scanline() / constScanline() or bits() / constBits(), but then you need to take care of the bit offsets for each 32-byte block of pixel values.
QImage is not an image format. It is a C++ class that lets C++ programmers manipulate images.
A QImage cannot be downloaded over the internet. A QImage can only exist in a program that's written with Qt.
File names like "main-qimg-salad" are not related to QImage. (Yes, I know the both start with a 'Q' and end with "image/"img", but really: they are not related at all.)
If you search https://www.google.com/search?q="main-qimg" you will find that most of these images are actually JPEG files. So, try renaming your file from "main-qimg-salad" to "main-qimg-salad.jpg" and see what happens.
There's no way to loselessly convert 16 bit integers into 8 bit integers, so you can't use QImage to display your image without dropping some of the information. I advise to follow @SGaist's advice and research what OpenGL provides and if that will suit your needs.
Ubuntu 14.? provides older Qt version than the one you use!
You should either provide Qt libraries which are used by your application or use Ubuntu Qt libraries to build your app if you use same Ubuntu version.
I was able to resolve the issue by changing the QCameraViewFinderSettings on my QCamera to use QVideoFrame::Format_ARGB32 @ 1920x1080. After this change, the QVideoFrame reported the proper number of mappedBytes.
One interesting note, I had to QCameraViewFinderSettings.setMinimumFrameRate(0). For some reason there was a lag on the viewfinder in low light, but changing this setting fixed it.
Just don't create it on heap. QPixmap is implicitly shared.
It does not matter how you create pixmap. What does is total number of allocated resources.
Changes to your code might fix something if your previous code did not clean the memory -did not delete pixmap.
So code causing problem was not posted.
Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.