[Qt-interest] How to fill the background of QImage with color without loosing its foreground contents

tangke tangk at lemote.com
Sat Aug 1 12:15:12 CEST 2009


sorry.I don't know what your means?

tangke
best regards

On 07/31/2009 11:39 PM, varun singh wrote:
> hi,
>
>    Well, i'm trying to make a painting application. I'm getting some trouble with setting the background color.
>
>    I've used QImage object as my painting space, hence i used QImage->fill() fuction to fill the QImage with a particular color.
>
>    But, if i scribble something on QImage (with Pen) and then use fill function, it clears everything n fills the image with the new color (well, that's obvious)...
>
>    Hence I've run nested for loops to access each pixel of QImage and check whether it is already colored with Pen, if it is not then i call setPixel() function to color it with background color.
>
>    But its not working, each pixel is still getting painted.
>
> Here is the code
>
> ******************************************************************************
> //mBColor is of type QRgb.
> void PaintWidget::setBColor(QRgb color) //sets the Background Color
> {
>      mBColor = color;
>      int x, y;
>      for(x = 0; x<= mPaintImage->width() - 1; x++)
>      {
>          for(y = 0; y<= mPaintImage->height() - 1; y++)
>          {
>              if(QColor(mPaintImage->pixel(x, y)) != mFColor) //mFColor is
>              {                                               //Foregournd
>                  mPaintImage->setPixel(x, y, mBColor);       //Ccolor.
>              }
>          }
>      }
>     emit bColorChanged(mBColor);
>     update();
> }
>
> *******************************************************************************
>
>    I'm Desperately looking for some help.
>
> -Varun
>
>
>
>        Looking for local information? Find it on Yahoo! Local http://in.local.yahoo.com/
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>    




More information about the Qt-interest-old mailing list