私はQt GUI上に一連のQLabel
オブジェクトを持っており、それらをHBITMAPオブジェクトで埋めます。これらのHBITMAPはメモリ上のバッファであり、ディスク上には存在しません。QLabelに配置されたHBitmapを削除する
今私はQPixmap
の fromWinHBITMAP
to create a
QPixmapのwhich I can then pass to the
QLabel s
setPixmap`関数を使用します。
今、QLabelの現在のイメージはどうなりますか?別のイメージで上書きすると、メモリに残りますか?削除されますか?
私のプログラムは約1時間実行した後に膨大な割合で成長するため、削除されないと思われます。 (1.7GB)をメモリに格納します。
変換を行うコードは次のとおりです。
//buffer is a map of QLabels which are filled with images.
void LoadPixmapFromBitmap(HBITMAP hBitmap, std::map<int, QLabel*>& buffer, int pixmapindex)
{
QPixmap pix;
pix = QPixmap::fromWinHBITMAP(hBitmap);
QPixmap temp(pix);
QSize sz(164, 121);
QPixmap resized(temp.scaled(sz));
QMatrix rotation;
rotation.rotate(90);
QPixmap rotated = resized.transformed(rotation);
//an attempt to delete the previous image properly and put in a new one. This doesn't seem to work.
if (buffer[pixmapindex]->pixmap() != NULL)
{
HBITMAP hbtmp = buffer[pixmapindex]->pixmap()->toWinHBITMAP();
buffer[pixmapindex]->clear();
HDC dc = GetDC(this->winId());
//HBITMAP p_old = SelectObject(dc, hbtmp);
BOOL deleted = DeleteObject(hbtmp);
if (!deleted)
PrintMsg("temp not deleted");
}
//////////////////////////////////end of attempt
buffer[pixmapindex]->setPixmap(rotated);
BOOL success = DeleteObject(hBitmap);
if (!success)
PrintMsg("hBitmap was not deleted");
}
私は上記の関数の最後に元のビットマップのハンドルを持つ 'DeleteObject'を呼び出していますが、それで十分ですか? –
@TonyTheLion、する必要があります。また、すべての変換を 'toWinHBITMAP'に落とします。それは実際には役に立たない – Lol4t0