From 53cfc13c9163ce22a5c06c8a9688852ef4a3908f Mon Sep 17 00:00:00 2001 From: xland <412588801@qq.com> Date: Thu, 2 Jan 2025 17:06:57 +0800 Subject: [PATCH] release img --- App/Util.cpp | 85 ++++++++++++++++++--------------------- App/Util.h | 4 +- Shape/ShapeMosaicLine.cpp | 6 +-- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/App/Util.cpp b/App/Util.cpp index c3546815..b6b01965 100644 --- a/App/Util.cpp +++ b/App/Util.cpp @@ -34,52 +34,47 @@ QMouseEvent Util::createMouseEvent(const LPARAM& lParam, const QEvent::Type& typ return QMouseEvent(type, p, g, btn, btn, mf); } -QImage Util::printWindow(WinBox* win) -{ - HDC hScreen = GetDC(win->hwnd); - HDC hDC = CreateCompatibleDC(hScreen); - HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, win->w, win->h); - DeleteObject(SelectObject(hDC, hBitmap)); - auto flag = PrintWindow(win->hwnd, hDC, PW_RENDERFULLCONTENT); - spdlog::info("PrintWindow {}",flag); - auto img = QImage(win->w, win->h, QImage::Format_ARGB32); - BITMAPINFO info = { sizeof(BITMAPINFOHEADER), (long)win->w, 0 - (long)win->h, 1, 32, BI_RGB, (DWORD)win->w * 4 * win->h, 0, 0, 0, 0 }; - GetDIBits(hDC, hBitmap, 0, win->h, img.bits(), &info, DIB_RGB_COLORS); - DeleteDC(hDC); - DeleteObject(hBitmap); - ReleaseDC(NULL, hScreen); - return img; -} - -QImage Util::printWindow2(WinBox* win) -{ - //auto dwmCapture = new DWMCapture(); - //auto hr = dwmCapture->Init(); - //if (FAILED(hr)) { - // delete dwmCapture; - //} - //BOX* box = nullptr; - //CAPTURE_DATA* data = new CAPTURE_DATA(); - //dwmCapture->CaptureWindow(win->hwnd, box, data); - - - - HDC hdcSrc = GetWindowDC(win->hwnd); - HDC hdcDest = CreateCompatibleDC(hdcSrc); - HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc, win->w, win->h); - auto hOld = SelectObject(hdcDest, hBitmap); - BitBlt(hdcDest, 0, 0, win->w, win->h, hdcSrc, 0, 0, SRCCOPY); - - auto img = QImage(win->w, win->h, QImage::Format_ARGB32); - BITMAPINFO info = { sizeof(BITMAPINFOHEADER), (long)win->w, 0 - (long)win->h, 1, 32, BI_RGB, (DWORD)win->w * 4 * win->h, 0, 0, 0, 0 }; - GetDIBits(hdcDest, hBitmap, 0, win->h, img.bits(), &info, DIB_RGB_COLORS); +//QImage Util::printWindow(WinBox* win) +//{ +// HDC hScreen = GetDC(win->hwnd); +// HDC hDC = CreateCompatibleDC(hScreen); +// HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, win->w, win->h); +// DeleteObject(SelectObject(hDC, hBitmap)); +// auto flag = PrintWindow(win->hwnd, hDC, PW_RENDERFULLCONTENT); +// spdlog::info("PrintWindow {}",flag); +// auto img = QImage(win->w, win->h, QImage::Format_ARGB32); +// BITMAPINFO info = { sizeof(BITMAPINFOHEADER), (long)win->w, 0 - (long)win->h, 1, 32, BI_RGB, (DWORD)win->w * 4 * win->h, 0, 0, 0, 0 }; +// GetDIBits(hDC, hBitmap, 0, win->h, img.bits(), &info, DIB_RGB_COLORS); +// DeleteDC(hDC); +// DeleteObject(hBitmap); +// ReleaseDC(NULL, hScreen); +// return img; +//} - SelectObject(hdcDest, hOld); - DeleteDC(hdcDest); - DeleteObject(hBitmap); - ReleaseDC(win->hwnd, hdcSrc); - return img; -} +//QImage Util::printWindow2(WinBox* win) +//{ +// //auto dwmCapture = new DWMCapture(); +// //auto hr = dwmCapture->Init(); +// //if (FAILED(hr)) { +// // delete dwmCapture; +// //} +// //BOX* box = nullptr; +// //CAPTURE_DATA* data = new CAPTURE_DATA(); +// //dwmCapture->CaptureWindow(win->hwnd, box, data); +// HDC hdcSrc = GetWindowDC(win->hwnd); +// HDC hdcDest = CreateCompatibleDC(hdcSrc); +// HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc, win->w, win->h); +// auto hOld = SelectObject(hdcDest, hBitmap); +// BitBlt(hdcDest, 0, 0, win->w, win->h, hdcSrc, 0, 0, SRCCOPY); +// auto img = QImage(win->w, win->h, QImage::Format_ARGB32); +// BITMAPINFO info = { sizeof(BITMAPINFOHEADER), (long)win->w, 0 - (long)win->h, 1, 32, BI_RGB, (DWORD)win->w * 4 * win->h, 0, 0, 0, 0 }; +// GetDIBits(hdcDest, hBitmap, 0, win->h, img.bits(), &info, DIB_RGB_COLORS); +// SelectObject(hdcDest, hOld); +// DeleteDC(hdcDest); +// DeleteObject(hBitmap); +// ReleaseDC(win->hwnd, hdcSrc); +// return img; +//} QImage Util::printScreen(const int& x, const int& y, const int& w, const int& h) { diff --git a/App/Util.h b/App/Util.h index 55f344f6..5800d32c 100644 --- a/App/Util.h +++ b/App/Util.h @@ -12,8 +12,8 @@ class Util public: static QMouseEvent createMouseEvent(const QEvent::Type& type = QEvent::MouseMove, const Qt::MouseButton& btn = Qt::MouseButton::LeftButton); static QMouseEvent createMouseEvent(const LPARAM& lParam, const QEvent::Type& type, const Qt::MouseButton& btn = Qt::MouseButton::LeftButton); - static QImage printWindow(WinBox* win); - static QImage printWindow2(WinBox* win); + //static QImage printWindow(WinBox* win); + //static QImage printWindow2(WinBox* win); static QImage printScreen(const int& x, const int& y, const int& w, const int& h); static void imgToClipboard(const QImage& img); static bool posInScreen(const int& x, const int& y); diff --git a/Shape/ShapeMosaicLine.cpp b/Shape/ShapeMosaicLine.cpp index 9fbb192b..0c50fb7b 100644 --- a/Shape/ShapeMosaicLine.cpp +++ b/Shape/ShapeMosaicLine.cpp @@ -51,8 +51,8 @@ void ShapeMosaicLine::mouseRelease(QMouseEvent* event) else { painter.drawImage(QPoint(0, 0), winImg.copy(pathRect.toRect())); } - mosaicImg = QImage(0,0); - winImg = QImage(0, 0); + mosaicImg = QImage(); + winImg = QImage(); if (state == ShapeState::sizing0) { QPainterPath tempPath; @@ -93,7 +93,7 @@ void ShapeMosaicLine::mousePress(QMouseEvent* event) event->accept(); } else if (hoverDraggerIndex >= 0) { - imgPatch = QImage(0, 0); + imgPatch = QImage(); createMosaicImg(); pressPos = event->position(); state = (ShapeState)((int)ShapeState::sizing0 + hoverDraggerIndex);