Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Black-Panther

Alter Hase

  • »Black-Panther« ist der Autor dieses Themas

Beiträge: 1 443

Wohnort: Innsbruck

  • Private Nachricht senden

1

03.03.2007, 14:24

24bit bmp speichern

Hi!

Gibt es schon eine Funktion die eine Texture/Surface als 24Bit BMP abspeichern kann?
Hab bis jetzt D3DXSaveSurfaceToFile verwendet, doch bin ich draufgekommen, dass diese 32Bit-BMPs erstellt und hab keinen Parameter gefunden, mit welchem sich das umstellen ließe... Hoffe ihr kennt da was... im Notfall, muss ichs halt selbst schreiben... ;)
stillalive studios
Drone Swarm (32.000 Dronen gleichzeitig steuern!)
facebook, twitter

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

2

03.03.2007, 15:01

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// .h


namespace bmp
{

    typedef unsigned short word;
    typedef unsigned long dword;

#pragma pack( 1 )

    struct BMPFileHeader
    {
        word    bfType;
        dword   bfSize;
        word    bfReserved1;
        word    bfReserved2;
        dword   bfOffBits;
    };

    struct BMPInfoHeader
    {
        dword   biSize;
        long    biWidth;
        long    biHeight;
        word    biPlanes;
        word    biBitCount;
        dword   biCompression;
        dword   biSizeImage;
        long    biXPelsPerMeter;
        long    biYPelsPerMeter;
        dword   biClrUsed;
        dword   biClrImportant;
    }; 

#pragma pack()

    bool saveBMP( const char* fileName, dword* pBmp, int width, int height );

}

// .cpp


bool bmp::saveBMP( const char* fileName, dword* pBmp, int width, int height )
{
    if( pBmp == 0 )
        return false;

    FILE* file = fopen( fileName, "wb" );

    if( file == 0 )
        return false;

    BMPFileHeader header;
    BMPInfoHeader info;
    int padding = ( width * 3 ) % 4;

    if( padding )
        padding = 4 - padding;

    header.bfType = 19778;
    header.bfSize = sizeof( BMPFileHeader ) + sizeof( BMPInfoHeader ) + (3 * width + padding) * height;
    header.bfReserved1 = 0;
    header.bfReserved2 = 0;
    header.bfOffBits = sizeof( BMPFileHeader ) + sizeof( BMPInfoHeader );

    info.biSize = sizeof( BMPInfoHeader );
    info.biWidth = width;
    info.biHeight = height;
    info.biPlanes = 1;
    info.biBitCount = 24;
    info.biCompression = 0;
    info.biSizeImage = 0;
    info.biXPelsPerMeter = 0;
    info.biYPelsPerMeter = 0;
    info.biClrUsed = 0;
    info.biClrImportant = 0;

    fwrite( &header, sizeof( BMPFileHeader ), 1, file );
    fwrite( &info, sizeof( BMPInfoHeader ), 1, file );

    for( int y = height - 1; y >= 0; --y )
    {
        dword* scanline = pBmp + y * width;

        for( int x = 0; x < width; ++x )
        {
            fwrite( scanline++, 3, 1, file );
        }

        char pad = 0;

        fwrite( &pad, 1, padding, file );

    }

    fclose( file );

    return true;
}


;)