PDA

View Full Version : QPixmap xx.scaledToWidth dont Scale but load...



patrik08
25th June 2006, 22:18
I wand to scale an image on my CMS is this to much work if scale slot is a qslider

or is int width QSize and not pixel?

scaledToWidth ( int width, Qt::TransformationMode mode = Qt::FastTransformation ) const



/* header */
private:
Gui_Image( QWidget* = 0 );
QImage image;
QPixmap myPixmap;
QSize actual;
/* header ..... */

/* i load image */

fileName = OpenFile("Image (*.png)");

if (!fileName.isEmpty()) {
connect(horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(ModpicsChanged(int)));
...
centrale->setPixmap(QPixmap::fromImage(image));
...
centrale->adjustSize();

actual = centrale->pixmap()->size();
...
horizontalSlider->setSliderPosition(wi);
...
}
/* ..... */

void Gui_Image::ModpicsChanged(int newvalue_w) /* int from QSlider 20px steeps */
{
...
myPixmap = QPixmap::fromImage(image);
myPixmap.scaledToWidth(newvalue_w,Qt::FastTransfor mation);
centrale->setPixmap(myPixmap); /* label */
centrale->adjustSize(); /* label */
actual = centrale->pixmap()->size();
...
}

jacek
25th June 2006, 22:36
Why do you use both QImage and QPixmap?
Conversion between QImage and QPixmap costs, especially on X Windows, so better use only QPixmaps (unless you have to access individual pixels).

Have you read QPixmap::scaledToWidth() docs?
If yes, do it again, but this time very carefully. Pay attention especially to the "const" keyword at the end of signature and the return type.

patrik08
25th June 2006, 23:05
Why do you use both QImage and QPixmap?
Conversion between QImage and QPixmap costs, especially on X Windows, so better use only QPixmaps (unless you have to access individual pixels).

Have you read QPixmap::scaledToWidth() docs?
If yes, do it again, but this time very carefully. Pay attention especially to the "const" keyword at the end of signature and the return type.

if const at end i make a copy is right? ... now run ... ist very fast on transform... :)
now qt4 taken moore points .... as Imagemagic on server..

But now to save i must go toImage () const : QImage ... QPixmap dont save ... not found


bool save ( const QString & fileName, const char * format, int quality = -1 ) const

/* running so ..*/

void Gui_Image::ModpicsChanged(int newvalue_w) /* int from QSlider 20px steeps */
{
qDebug() << "### copyofimagefile... " << copyofimagefile;
QPixmap pic(copyofimagefile);
QPixmap scaled = pic.scaledToWidth(newvalue_w);
centrale->setPixmap(scaled); /* label */
centrale->adjustSize(); /* label */
actual = centrale->pixmap()->size();
qDebug() << "### Draw image and dispay new W x H px... ";
}

jacek
25th June 2006, 23:10
if const at end i make a copy is right?
Not quite, const means that this method can't change the object.

http://www.parashift.com/c++-faq-lite/const-correctness.html


But now to save i must go toImage ()
No, you don't: QPixmap::save()

patrik08
25th June 2006, 23:21
Not quite, const means that this method can't change the object.


I see is the same as a define on php but on objekt...



No, you don't: QPixmap::save()

Ok and quality is same as gimp 70-80...

Much tanks....