From 83d0dc75c67f67d5066db8ea5580526f3f144c08 Mon Sep 17 00:00:00 2001 From: murat Date: Mon, 20 Jul 2020 16:20:48 +0200 Subject: [PATCH] Fix Qt screenhot crash --- include/utils/ImageData.h | 4 +++- libsrc/grabber/qt/QtGrabber.cpp | 1 + libsrc/utils/ImageResampler.cpp | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/utils/ImageData.h b/include/utils/ImageData.h index aad498762..f1cc3f598 100644 --- a/include/utils/ImageData.h +++ b/include/utils/ImageData.h @@ -136,7 +136,9 @@ class ImageData : public QSharedData void toRgb(ImageData& image) { - image.resize(_width, _height); + if (image.width() != _width || image.height() != _height) + image.resize(_width, _height); + const unsigned imageSize = _width * _height; for (unsigned idx = 0; idx < imageSize; idx++) diff --git a/libsrc/grabber/qt/QtGrabber.cpp b/libsrc/grabber/qt/QtGrabber.cpp index 1f24aa13c..75803f27b 100644 --- a/libsrc/grabber/qt/QtGrabber.cpp +++ b/libsrc/grabber/qt/QtGrabber.cpp @@ -101,6 +101,7 @@ int QtGrabber::grabFrame(Image & image) QPixmap originalPixmap = _screen->grabWindow(0, _src_x, _src_y, _src_x_max, _src_y_max); QPixmap resizedPixmap = originalPixmap.scaled(_width,_height); QImage imageFrame = resizedPixmap.toImage().convertToFormat( QImage::Format_RGB888); + image.resize(imageFrame.width(), imageFrame.height()); for (int y=0; y> 1) + _horizontalDecimation - 1) / _horizontalDecimation; int outputHeight = (height - _cropTop - cropBottom - (_verticalDecimation >> 1) + _verticalDecimation - 1) / _verticalDecimation; - outputImage.resize(outputWidth, outputHeight); + + if (outputImage.width() != outputWidth || outputImage.height() != outputHeight) + outputImage.resize(outputWidth, outputHeight); for (int yDest = 0, ySource = _cropTop + (_verticalDecimation >> 1); yDest < outputHeight; ySource += _verticalDecimation, ++yDest) {