class Viewer : public QWidget{...public slots: void zoomIn();protected: QImage *image; QImage *t_image; QPainter painter; void paintEvent(QPaintEvent * event); qreal zoom_value; // коэф. масштабирования};--------------------------------Viewer::Viewer(QWidget *parent) : QWidget(parent){ zoom_value = 1.0; image = new QImage(); t_image = new QImage(); if(image->load("...jpg")){ t_image->operator = (*image); if(!t_image->isNull()){ setGeometry(QRect(0,0,t_image->width(),t_image->height())); } }}void Viewer::paintEvent(QPaintEvent *event){ qDebug()<<"paint:"; if(!t_image->isNull()){ qDebug()<<" draw image"; painter.begin(this); painter.drawImage(0,0,*t_image); painter.end(); } else qDebug()<<" image is null";}void Viewer::zoomIn(){ if(!t_image->isNull()){ QMatrix matrix; zoom_value*=1.3; t_image->operator = (image->transformed(matrix.scale(zoom_value,zoom_value))); while(t_image->isNull()){ zoom_value/=1.3; qDebug()<<" image is null, zoom value = "<<zoom_value; t_image->operator =(image->transformed(matrix.scale(zoom_value,zoom_value))); } qDebug()<<"transform image["<<image->size()<<"] to ["<<t_image->size()<<"]"; qDebug()<<" image is OK, zoom value = "<<zoom_value; setGeometry(QRect(0,0,t_image->width(),t_image->height())); update(); }}
transform image[ QSize(800, 600) ] to [ QSize(1040, 780) ] image is OK, zoom value = 1.3 paint: draw image // изображение увеличелось...transform image[ QSize(800, 600) ] to [ QSize(11029, 8272) ] image is OK, zoom value = 13.7858 paint: draw image // изображение увеличелосьQImage: out of memory, returning null image image is null, zoom value = 13.7858 ...QImage: out of memory, returning null image image is null, zoom value = 0.0725382 transform image[ QSize(800, 600) ] to [ QSize(14337, 10753) ] image is OK, zoom value = 0.0725382 paint: draw image // изображение увеличелось!!!transform image[ QSize(800, 600) ] to [ QSize(75, 57) ] image is OK, zoom value = 0.0942996 paint: draw image // изображение уменьшилось от исходного в zoom value = 0.0942996 раз transform image[ QSize(800, 600) ] to [ QSize(98, 74) ] image is OK, zoom value = 0.122589 paint: draw image // изображение увеличелосьитд
t_image->operator = (*image);...t_image->operator =(image->transformed(matrix.scale(zoom_value,zoom_value)));
*t_image = *image;...*t_image = image->transformed(matrix.scale(zoom_value,zoom_value);
*t_image = image->copy(); // если уж хочется скопировать, хотя не видно зачем...*t_image = image->transformed(matrix.scale(zoom_value,zoom_value);
painter.begin(this); painter.scale(zoom_value,zoom_value) painter.drawImage(0,0,*t_image); painter.end();
if (t_image.isNull()){ zoom_value = 1.0; qDebug() << " image is null, zoom value = " << zoom_value; t_image = image; } else { CODE }
if(t_image.isNull()){ zoom_value/=1.3; qDebug()<<" image is null, zoom value = "<<zoom_value; t_image = image.transformed(matrix.scale(zoom_value, zoom_value)); } //else { CODE //}
while(t_image.isNull()){ zoom_value/=1.3; qDebug()<<" image is null, zoom value = "<<zoom_value; t_image = image.transformed(matrix.scale(zoom_value, zoom_value)); } //else { CODE //}
void Widget::paintEvent ( QPaintEvent * event ) {... painter.drawImage(QRect(0,0,width(),height()),image);...}