You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

mick

Trainee

  • "mick" started this thread

Posts: 55

Location: Vancouver, BC, Canada

Occupation: Biologist

  • Send private message

1

Sunday, October 16th 2005, 11:09pm

make a qimage (or a qpixmap) grayscale

Hi,

I have a full-color QImage that I want to make grayscale.
If there is a way of doing this for qpixmap, I can use that because I convert from QImage to QPixmap before rendering to screen.

How do I do it?

Thanks!

Mick

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

2

Monday, October 17th 2005, 8:40am

RE: make a qimage (or a qpixmap) grayscale

QImage::convertToFormat in Qt4. For Qt3 iterating over rows and columns and converting each pixel to gray would probably be the easiest.

mick

Trainee

  • "mick" started this thread

Posts: 55

Location: Vancouver, BC, Canada

Occupation: Biologist

  • Send private message

3

Thursday, October 27th 2005, 4:59pm

RE: make a qimage (or a qpixmap) grayscale

Thanks wysota!

4

Tuesday, May 23rd 2006, 8:24pm

I am having an issue with a Grayscale bitmap on Windows. I can open it correctly on Unix, but Windows will not open it as grayscale ( Monocrome only ). Do you know what might cause this?

Thanks,

SoreFoot


Side notes of possible interest
1) if i try to open as a Qt::Color QPixmap it simply returns a null QPixmap

5

Wednesday, July 5th 2006, 3:39pm

RE: make a qimage (or a qpixmap) grayscale

Quoted

Originally posted by wysota
QImage::convertToFormat in Qt4. For Qt3 iterating over rows and columns and converting each pixel to gray would probably be the easiest.


Could you write the code portion to make a grayscale with convertToFormat? Any of my test did not work :(

6

Wednesday, July 5th 2006, 3:44pm

I apologize for my slow reply, but the issue comes from having a bitmap too big for your video card memory. The bitmaps I had were heading into the GB range, and obviously my video card did not have enough memory to support this. As a work around, I have a QImage hold the entire bitmap then use a QPixmap to hold the portion I am actually displaying.

SoreFoot

P.S. the code has undergone so many iteration that the segment you are referencing is no longer a piece.

7

Wednesday, October 4th 2006, 3:01pm

RE: make a qimage (or a qpixmap) grayscale

hello,
I have an image whicgh is in 24 bit format and I would like to convert it to a gray scale value, I used the convertToFormat but it does not work for me. my image is stored in QImage. could you suggest me something.

thanx in advance

8

Thursday, October 5th 2006, 9:06am

RE: make a qimage (or a qpixmap) grayscale

hi,

I have a QImage which is a color image with depth of 32bpp and want to convert it to a grayscale picture. I will explain in detail.
I have a coulr bmp picture , a red circle in a white background. with 16 million pixels. this picture is loaded and saved as a Qimage. after loading I checked the depth and found it as 32. now I use the function
"m_imageSrc= m_imageSrc.convertToFormat(QImage::Format_Indexed8,ColorTab,Qt::ThresholdDi
ther );"
(the reason why i used Threshold dither is becasue withthis i was getting the picture without any noise, while with other option i was getting some noise in my picture)
and the resulting m_imagesrc (also a QImage) is a bmp picture with depth of 8bpp, but the strange thing is that the colour of the circle is still red (which should not be the case in a grayscale image.).. can you suggest anything for this.
further I used the fuction of

"m_imageSrc.setColorTable(ColorTab);" // with color tab declared upto 256
now the red circle transforms to dark gray , but the problem is that even the white background is changed to light gray.

after doing all this I now convert my QImage to Qpixel for displaying on the label.

my requirement was to have the QImage converted to the 8bpp and also change from redcolour to greyscale, just like it does in any of the photoshop software.

hope you understand my mail coz have written is haphazardly, thanx in advance.

reagrds.

9

Thursday, October 5th 2006, 5:11pm

RE: make a qimage (or a qpixmap) grayscale

try the Mono format and see now it looks.

10

Saturday, December 19th 2009, 2:29pm

Hey. It is my sample of gray converting of 8ppt QImage. It is easily make version for other depth images.

void make_grayscale(QImage& in)
{
if(in.format()!=QImage::Format_Indexed8)
throw "format error";
QVector<int> transform_table(in.numColors());
for(int i=0;i<in.numColors();i++)
{
QRgb c1=in.color(i);
int avg=qGray(c1);
transform_table=avg;
}
in.setNumColors(256);
for(int i=0;i<256;i++)
in.setColor(i,qRgb(i,i,i));
for(int i=0;i<in.numBytes();i++)
{
in.bits()[i]=transform_table[in.bits()[i]];
}
}
[/i][/i]