Bitmap um 90° drehen?



  • Hallo,
    wie kann ich ein Bitmap (ich habe das Handle) um 90° drehen?
    Ich habe keine passende GDI-Funktion gefunden, muss ich das "von Hand" machen?

    MfG





  • Hallo,
    danke für deine Antwort, dass es so kompliziert ist, dachte ich nicht 😃 .
    Da ich aber nur 90° brauche, habe ich eine extra Funktion geschrieben:

    HBITMAP Create90RotatedBitmap(HBITMAP hBit, bool bRotateLeft)
    {
        BITMAP  bitmap;
        HDC     hdc, hdcRotated;
        HGDIOBJ hOldGdiObj1, hOldGdiObj2;
        HBITMAP hBitRotated;
    
        GetObject(hBit, sizeof(BITMAP), &bitmap);
    
        hdc = CreateCompatibleDC(0);
        hdcRotated = CreateCompatibleDC(0);
    
        hBitRotated = CreateBitmap(bitmap.bmHeight, bitmap.bmWidth,
                            bitmap.bmPlanes, bitmap.bmBitsPixel, 0);
    
        hOldGdiObj1 = SelectObject(hdc, hBit);
        hOldGdiObj2 = SelectObject(hdcRotated, hBitRotated);
    
        int i, j;
        if(bRotateLeft)
        {
            for(j = 0; j < bitmap.bmHeight; j++)
            {
                for(i = 0; i < bitmap.bmWidth; i++)
                    SetPixel(hdcRotated, j, bitmap.bmWidth - i - 1,
                                GetPixel(hdc, i, j));
            }
        }
        else
        {
            for(j = 0; j < bitmap.bmWidth; j++)
            {
                for(i = 0; i < bitmap.bmHeight; i++)
                    SetPixel(hdcRotated, bitmap.bmHeight - i - 1, j,
                                GetPixel(hdc, j, i));
            }
        }
    
        SelectObject(hdc, hOldGdiObj1);
        SelectObject(hdcRotated, hOldGdiObj2);
    
        DeleteDC(hdc);
        DeleteDC(hdcRotated);
    
        return hBitRotated;
    }
    

    Ich denke, jedesmal in WM_PAINT das Bitmap zu drehen, dauert sehr lange, deshalb erstelle ich mit der Funktion ein 2. Bitmap, welches später mit DeleteObject() gelöscht werden muss.
    Aber leider dauert das ganze bei größeren Bitmaps eine Ewigkeit 😞 .
    Ist das normal, oder gibts da eine bessere Lösung?

    MfG

    [ Dieser Beitrag wurde am 28.12.2002 um 13:44 Uhr von Black Shadow editiert. ]



  • ja ne is klar, wenn du SetPixel verwendest. machs mit nem DIB



  • Danke,
    aber ich weiß jetzt, was du meinst...
    Welche Funktionen soll ich verwenden?


Anmelden zum Antworten