I'm working on an application that takes shows a live feed from an 18 Megapixel IDS uEye Camera.
The three options that I have for displaying the image are 1) Using a Direct3D method from the API to draw to a QWidget using (HWND)QWidget->winId(). 2) Using a Bitmap Rendering method from the API to draw to a QWidget using (HWND)QWidget->winId(). 3) Creating a QImage from the raw sensor data (a char* buffer) and updating the GUI with the QImage.
Because I would like to use the features of the QImage class for my application, I am currently pursuing that last option.
I am able to successfully convert the image from the camera with the following code:
// Collect the image.
int nRet = is_GetImageMem(m_hCam, &m_pcLongImageMemory);
if( nRet != IS_SUCCESS)
{
// handle error
}
//Put in unique_ptr<> to QImage
img.reset((new QImage((uchar*)m_pcImageMemory, m_nSizeX, m_nSizeY, QImage::Format::Format_RGB888)));
ui.widget->setImage(img.get());
This does fine in terms of generating the image that I will use. I then want to paint the image to a QWidget. For this, following advice from this thread, I have been able to successfully take these large, 18 MP images and update the GUI with them.
So, my problem arises with the following method:
void ImageFrame::paintEvent(QPaintEvent*) {
if (!m_image) { return; }
QPainter painter(this);
painter.drawImage(this->rect(), *m_image, m_image->rect());
}
My problem is with the adjustments made by the QPainter::paintImage() method being used. It seems that most of the overloads for ::paintImage() will automatically stretch the image to fit the bounding rectangle. In my case, I would prefer to maintain the 4:3 aspect ratio of my image at all times to avoid any distortion for the user. In this case, I have not found a QRect() configuration that will allow me to update the GUI with this image without stretching.
It seems like my options are either to rescale the image to the size of the widget in the GUI (which seems very, very expensive with an image this size) or else to find a way to fix the size of this QWidget subclass so that it always scales into the maximum 4:3 ratio configuration it can within its surrounding layout...
Any help or insight that someone might be able to provide is appreciated.