[Qt-interest] Getting number of pixels in a QImage

Rainer Wiesenfarth Rainer.Wiesenfarth at inpho.de
Tue Apr 7 08:31:58 CEST 2009


Upps! Forget what I wrote, I mixed the x, y order with the order we use in
our software which usually does row, column ...

So, the reason is different. What do you get for width() and height() and
which size is the image? Is this the original code "as is" or a simplified
version?

From: qt-interest-bounces at trolltech.com 
> From: Keshava Krishna [mailto:keshavkrishna88 at gmail.com] 
> > @Rainer,
> > 
> > have a look at the code...
> > 
> > QColor *pixelColor;
> >  int c;
> > image=new QImage(imageFileName);
> > for(int i=0;i<image->width();i++)
> > {
> >       for(int j=0;j<image->height();j++)
> >         {
> > 
> >                     pixelColor = new QColor(image->pixel(i,j));
> >                     pixelColor->setAlphaF(0.3);
> >                      c = pixelColor->rgba();
> >                      image->setPixel(i,j,c);
> >           }
> > }
> > [...]
> 
> You swapped row and column of the image. So either i should 
> run from 0 to
> height() and j from 0 to width(), or the calls should be 
> pixel(j,i) and
> setPixel(j,i,c).
> 
> See what a code snippet can do to solve your problem? ;-)

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
place of business: Stuttgart * managing director: Johannes Saile
commercial register: Stuttgart, HRB 9586
Leader in Photogrammetry and Digital Surface Modelling
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3359 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090407/d602d6b5/attachment.bin 


More information about the Qt-interest-old mailing list