ich eine Methode, dies zu tun, wo ich die roten und blauen Bytes umgedreht, verwendet dann den folgenden Code aus einer zu einem QPixmap Gdiplus :: Bitmap zu konvertieren: aber
QPixmap getAsQPixmap(Gdiplus::Bitmap bitmap)
{
// One of my functions to flip blue and red bytes of the image
_flipBlueWithRed();
// m_pBytes is a pointer to an unsigned char that marks the start of the image
// It was retrieved from locking the Gdiplus::Bitmap
auto result = QPixmap::fromImage(QImage(m_pBytes, getWidth(), getHeight(), QImage::Format_RGB888));
// Restore data back to original state
_flipBlueWithRed();
return result;
}
dieser Methode, war langsam und dauerte gut 60 Millisekunden, um auszuführen. Meine neue Methode bestand also darin, die Gdiplus :: Bitmap in eine Datei zu speichern und den Pfad zu dieser Datei aus dem QPixmap-Konstruktor heraus zu lesen. Diese Methode ist VIEL schneller, etwa 5 Millisekunden.
QPixmap getAsQPixmap(GdiPlus::Bitmap bitmap)
{
std::string path = "C:/path_to_img.....png";
// One of my functions to unlock the Gdi+ bitmap
_unlockGdiPlusBitmap();
// Get Clsid
CLSID pngClsid;
getEncoderClsid(format_mime, &pngClsid);
// Save bitmap
// stringToWString() was a function that I wrote to convert a standard string to be a wide string
bitmap->Save(stringToWString(path).c_str(), static_cast<const CLSID*>(&pngClsid));
// Lock bitmap
_lockGdiPlusBitmap();
// Create the QPixmap
QPixmap new_img(path);
return new_img;
}