Re: Qt crash at drawImage
So none of the sizes of your images match. One is 216 x 560, one is 320 x 240, another is 360 x 260. What do you think will happen if you try to load one image of 360 x 260 into another image of 320 x 240, and then try to paint that into an image of 216 x 560? Do you expect QImage and QPainter to try to understand what you really want to do and just do it for you despite the fact that nothing matches?
Re: Qt crash at drawImage
The "rcptImage" is a sort of canvas I am using to use to either drawImage or drawText.
Sorry, that was a typo.
My image is 360 x 240, I mean the one I uploaded.
Anyways even after changing all sizes to 320x240, the crash is still happening...
Added after 8 minutes:
Also, the surprising thing is that, if use "img" with "drawImage", it works absolutely fine.
When I use "img1", it is crashing.
Re: Qt crash at drawImage
If your input image is 360 x 240 and the image you are trying to paint into is smaller (320 x 240), then it is still probably going to blow up.
Do you know that the image you say you loaded has actually been loaded (QImage::isNull()) or that the pointer returned by QImage::bits() is not NULL or that the image you create from the bits is not null??
Re: Qt crash at drawImage
I changed the canvas size to 500x500(rcptImage),
img.isNull() is false. I printed out img.Bits(), it has data and it is not Null
img1.isNull() is false. and img1.Bits() is not null.
I also looped through the bits and subtracted the pixel values of img and img1. The differences for all pixels are all zeros.
Also, img and img1 are both 320 x 240.. a total of 9600 bytes of data.
Another observation is that when I use loadFromData function with img1, i.e., tried the following
const uchar* temp = img.constBits();
QImage img1;
bool result = img1.loadFromData(temp, 9600, "BMP");
The result is false.
Added after 25 minutes:
Hi d_stranz,
I just tried couple of things, and when I changed the image format as follows, the program does not crash
QImage img1(tempData, 320, 240, QImage::Format_ARGB32);
When I use
QImage img1(tempData, 320, 240, QImage::Format_Mono);
there is a crash.
Why is this happening. As per my understanding, "QImage img("/home/chaitras/work/Printer/NipponPrinter/Printer_Test/test1.bmp");" is a QImage::Format_Mono. I confirmed this by printing "QImage::Format f = img.format();"
But when I read the get the img.bits() and create QImage img1(img.bits(), 320, 240, QImage::Format_Mono); it does not work..
Why is it like that? Do u have any idea on this??
Let me know your thoughts..
Re: Qt crash at drawImage
You have a mono input image and you appear to want an exact copy of that image. Why are you playing with the internal data buffer at all?
Should achieve the goal.
Re: Qt crash at drawImage
Thanks for your reply.
In my project, I am expecting the image as a byte stream. And I need to use this byte stream in to QImage and then print this image out.
So, I happened to write a small test program that intends to do this.
But, it is crashing at the mentioned point.
Could you please give an example as to how to load a byte stream into QImage and do a "drawImage"?