Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.10 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Deleting a HBitmap placed into a QLabel
  2. //buffer is a map of QLabels which are filled with images.
  3. void LoadPixmapFromBitmap(HBITMAP hBitmap, std::map<int, QLabel*>& buffer, int pixmapindex)
  4. {
  5.     QPixmap pix;
  6.     pix = QPixmap::fromWinHBITMAP(hBitmap);
  7.  
  8.     QPixmap temp(pix);      
  9.     QSize sz(164, 121);
  10.     QPixmap resized(temp.scaled(sz));
  11.  
  12.     QMatrix rotation;
  13.     rotation.rotate(90);
  14.     QPixmap rotated = resized.transformed(rotation);
  15.  
  16. //an attempt to delete the previous image properly and put in a new one.  This doesn't seem to work.
  17.     if (buffer[pixmapindex]->pixmap() != NULL)
  18.     {
  19.         HBITMAP hbtmp = buffer[pixmapindex]->pixmap()->toWinHBITMAP();
  20.         buffer[pixmapindex]->clear();
  21.  
  22.         HDC dc = GetDC(this->winId());
  23.         //HBITMAP p_old = SelectObject(dc, hbtmp);
  24.  
  25.         BOOL deleted = DeleteObject(hbtmp);
  26.         if (!deleted)
  27.             PrintMsg("temp not deleted");
  28.     }
  29.  
  30. //////////////////////////////////end of attempt
  31.     buffer[pixmapindex]->setPixmap(rotated);
  32.  
  33.     BOOL success = DeleteObject(hBitmap);
  34.     if (!success)
  35.         PrintMsg("hBitmap was not deleted");
  36. }