PDA

View Full Version : QPainter doing a distortion in drawed pixmap



Momergil
11th July 2014, 18:49
Hello!

I'm facing a strange problem with QPainter::drawPixmap usage. To use my debug situation, I downloaded a common-random bitmap (.bmp) from the web into my PC and put it in a subdirectory. If I call QPixmap::drawPixmap with a unaltered QPixmap created with the bitmap's file, it is drawed correctly on screen.

The problem is that I need to do some edittings on it and for that I'm using GIMP (I'm working in Linux). So, if I do such edittings (and, in accordance to my tests, actually any edit at all with GIMP) and then I try to print the image again using the same code, I get a blue-unchanged image instead o.O

Here is a print screen comparing the changed file with the original one:

10513

And here a print of the two files in the system folder, in the same order:

10514

At least visually one can see that is not GIMP who is distorting the image (and I actually found no reason for believing so).



I'm glad for any help in trying to solve this problem!

Momergil


------
Edit: Now I did other tests and I'm beginning to think that it's GIMP fault (while I don't have here any other image editor for linux to do the final checking and don't know which to download). Here are two other images comparing what I got and what Qt shows:

10515

And in the directory:

10516

The most interesting here is the last files, when I just opened the image in GIMP and clicked int File->Overwrite (without any edit) and this was enough for QPainter to draw the pixmap with that "blue color effect" :/

ChrisW67
11th July 2014, 23:04
Since we do not have the original BMP file, your code, or any idea what you are doing in Gimp, it is difficult to say.

It looks like the blue and red channels have been swapped. It also looks like you are fiddling with an alpha channel and this might cause a problem with BMP handling in Qt. If you convert to PNG then you might find the image works better.

Momergil
14th July 2014, 13:44
Since we do not have the original BMP file, your code, or any idea what you are doing in Gimp, it is difficult to say.

Well, actually I didn't post any of this since there is no special thing about what I did. I mean, regarding the image in Gimp, as I sad, it was enough to just open the bitmap and save it again without any real change in the image that the problem would already arise. Regarding the code, once again no special thing here; only load the pixmap with the file path and use QPainter::drawPixmap on it inside a paint event.


If you convert to PNG then you might find the image works better.

Well you're correct about that (I was avoiding PNG conversion because this project is not mine since its birth and it seems a convention that only bitmap images should be used); if I use a PNG image, then the blue effect doesn't appear anymore, but the real effect I want to implement (rounded corners) don't appear :p (I mean, I put the rounded corners but the image shown in the app is with squared corners as the original)

So I'll try another way of doing the round corners.

Thanks,

Momergil


EDIT: Btw, isn't there a way to do this rounded corners effect on Qt?
EDIT 2: Well actually there is a small "non-normality" that is actually causing the problem:



#define SET_PIXMAP(_s) QPixmap::fromImage(QPixmap(_s).toImage().convertTo Format(QImage::Format_RGB16))


I use such define where I load the QPixmap in order to force a RGB16 image since the hardware used in this project only supports such RGB configuration. If this is set, the rounded corners don't appear.