Frage

A user installed our application to a server PC, shared the install directory as network drive Z: and now opens the app from different client PCs all over his shop. Everything works fine except for a naggling bug on one of the PCs:

On the Problem PC, the app can load .jpg files for inventory items just fine and show the corresponding QPixmap in a QLabel. When the inventory item he is currently viewing does not yet have an image assigned to it, he can open a file dialog, choose an image and display that correctly. However, saving the (new/changed) QPixmap as a .jpg stores it to disc as a series of colored vertical lines on a black background:

(this should actually be some jewellery)

Saving is done via QPixmap::save( const QString & fileName, ...) with the file name set programmatically to "<some_id>.jpg" to designate the desired file format. Returns true, but the resulting file looks like modern art.

However, saving images works fine on the server and the other clients.

Both the server and the Problem PC run Windows XP at an identical patch level.

Process Explorer shows identical DLLs for the app process on server and Problem PC except for the Problem PC using dnsapi.dll, which the server doesn't.

Process Explorer also shows that on both server and client the Qt DLL used to deal with JPEGs is \Device\LanmanRedirector\<server>\<app>\plugins\imageformats\qjpeg4.dll, and a drive-wide search on the Problem PC for qjpeg*.dll came up empty, so the app should use the same JPEG handling code on both computers.

Any suggestions?

(EDIT: added OS and patch status to problem description.)

EDIT: Solution: on the problem machine we had a 16 bpp colour depth. Setting that to 32 bpp solved our problem instantly. I also replaced
_pm.save( sDestFileName )
with
_pm.toImage().convertToFormat( QImage::Format_RGB32 ).save( sDestFileName )
so that we won't run into this on every old client PC running less than 32 bpp.

War es hilfreich?

Lösung

Here are a few things to try to isolate the problem:

  • Copy qjpeg4.dll to the client's working directory
  • Is the image corrupted when saving as PNG or GIF?
  • Convert your data to a QImage and work from that.
  • Consider the byte format (I usually use ARGB32 because it is int-aligned)
  • To test where the problem occurs, you might try converting the image to JPG format then viewing it in a debugging window.

The function below is from an OSS program I wrote. You might try using it then displaying the contents of the QImage referred to in the second parameter:

//! Saves image with JPEG compression in given quality (0 - 100, Qt's scale)
//! @param[in] in The lossless input image
//! @param[out] out The image to save to using JPEG compression
//! @param quality The quality level (0 - 100, 0 the most compressed)
//! @return The size of the saved image
quint32 Window::imageSaveLossy(QImage &in, QImage &out, quint8 quality)
{
        quint32 retval;
        QByteArray ba;
        QBuffer buffer(&ba);
        buffer.open(QIODevice::WriteOnly);

        QImage temp(in.size(), QImage::Format_ARGB32);
        temp.fill(QColor(Qt::white).rgb());
        QPainter painter(&temp);
        painter.drawImage(0, 0, in);

        temp.save(&buffer, "JPG", quality);
        out.loadFromData(ba, "JPG");
        retval = (quint32)ba.size();
        buffer.close();
        return retval;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top