Results 1 to 2 of 2

Thread: How to clear or erase, drawn color from image

  1. #1
    Join Date
    Dec 2015
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to clear or erase, drawn color from image

    I am filling color on top of image. But this function will be called 10 sec once to fill different color.
    My issue is, Since previously filled color still exists on the image. The colors are overlapping every time.
    I want to clear the filled color before fill again.

    Qt Code:
    1. class GraphicsView_Layout : public QWidget
    2. {
    3. Q_OBJECT
    4.  
    5. QImage* mfloorImg;
    6. };
    7.  
    8. : QWidget(parent)
    9. {
    10. ui.setupUi(this);
    11. mfloorImg=new QImage("./img.jpg");
    12. }
    13.  
    14. //This function will be called every 10 sec once to fill different color.
    15. void QWidget::Fill_Area_With_Color(float* nPmv)
    16. {
    17. //Here I want to clear the previously drawn color
    18.  
    19. //Draw color
    20. QPainter painter(mfloorImg);
    21.  
    22. QColor areaColor;
    23. int nPos_X=0;
    24. int nPos_Y=0;
    25.  
    26. for(int i=0;i<g_area_count;i++)
    27. {
    28. int nblock_count=mBlock_Count[i];
    29. areaColor=Get_Area_Color(nPmv[i]);
    30. for(int j=0;j<nblock_count;j++)
    31. {
    32. nPos_X=mPtrCoordinates[i][j][0];
    33. nPos_Y=mPtrCoordinates[i][j][1];
    34. //painter.fillRect(QRect(nPos_X,nPos_Y,28,24),QBrush(areaColor));
    35. painter.fillRect(QRect(nPos_X,nPos_Y,28,24),QBrush(areaColor));
    36. }
    37. }
    38. m_gviewBasic->addImage(mfloorImg);
    39. emit Show_GraphicsView_Layout(true);
    40. QObject::connect(m_gviewBasic,SIGNAL(Mouse_Left_Button_Clicked(int,int)),this,SLOT(Mouse_Clicked(int,int)));
    41. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by vivek.nmit@gmail.com; 17th December 2015 at 06:02.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to clear or erase, drawn color from image

    You write into the image, so obviously the pixels in that image change.

    You can either load the image again, or keep the original image and always paint into a copy.

    Cheers,
    _

Similar Threads

  1. Replies: 15
    Last Post: 24th July 2015, 23:33
  2. Clear background color a tabwidget
    By smemamian in forum Newbie
    Replies: 2
    Last Post: 10th July 2013, 00:11
  3. QGLWidget won't display anything except the clear color
    By alexbcd in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2010, 07:01
  4. Need advice on getting HSI color from an Image
    By ramstormrage in forum Newbie
    Replies: 11
    Last Post: 4th May 2008, 14:26
  5. color image to negative
    By sm in forum Newbie
    Replies: 1
    Last Post: 29th January 2008, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.