<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bitmap speichern]]></title><description><![CDATA[<p>Ich habe hier eine funktion zum speichern von Bitmaps.<br />
Das Bitmap wird zwar erstellt ich kann es aber mit keinem Bildbetrachtungprogramm öffnen.</p>
<p>Was mach ich falsch?</p>
<pre><code class="language-cpp">void save(int height, int width, HDC hdc)
{
    BITMAPINFOHEADER bmih;
    BITMAPFILEHEADER bmfh;
    BITMAPINFO bi;
    HBITMAP aBmp;
    void *dibvalues;
    HGDIOBJ OldObj;
    HDC hdc2;
    DWORD bytes_write;
    DWORD bytes_written;
    HANDLE fileHandle;

    hdc2=CreateCompatibleDC(hdc);

    ZeroMemory(&amp;bmih,sizeof(BITMAPINFOHEADER));
    bmih.biSize=sizeof(BITMAPINFOHEADER);
    bmih.biHeight=height;
    bmih.biWidth=width;
    bmih.biPlanes=1;
    bmih.biBitCount=16;
    bmih.biCompression=BI_RGB; 
    bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * bmih.biHeight;
    bmih.biXPelsPerMeter = 0;
    bmih.biYPelsPerMeter = 0;
    bmih.biClrImportant = 0;

    bi.bmiHeader=bmih;

    aBmp=CreateDIBSection(hdc,&amp;bi,DIB_RGB_COLORS,(void**)&amp;dibvalues,NULL,NULL);

    OldObj=SelectObject(hdc2,aBmp);
    BitBlt(hdc2,0,0,width,height,hdc,0,0,SRCCOPY);

    ZeroMemory(&amp;bmfh,sizeof(BITMAPFILEHEADER));
    bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    bmfh.bfSize=(3*bmih.biHeight*bmih.biWidth)+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    bmfh.bfType=0x4d42;
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;

        fileHandle=CreateFile(&quot;test.bmp&quot;,GENERIC_READ | GENERIC_WRITE,(DWORD)0,NULL,
                                                    CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
    if (fileHandle==INVALID_HANDLE_VALUE)
    {
        OutputDebugString(&quot;CreateFile failed!\n&quot;);
    }

        // Write the BITMAPFILEHEADER
        bytes_write=sizeof(BITMAPFILEHEADER);
    if (!WriteFile(fileHandle,(void*)&amp;bmfh,bytes_write,&amp;bytes_written,NULL))
    {
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

        //Write the BITMAPINFOHEADER
    bytes_write=sizeof(BITMAPINFOHEADER);
    if (!WriteFile(fileHandle,(void*)&amp;bmih,bytes_write,&amp;bytes_written,NULL))
    {
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

        //Write the Color Index Array???
        bytes_write=bmih.biSizeImage;//3*bmih.biHeight*bmih.biWidth;
    if (!WriteFile(fileHandle,(void*)dibvalues,bytes_write,&amp;bytes_written,NULL))
    { 
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

    CloseHandle(fileHandle);

    DeleteObject(SelectObject(hdc2,OldObj));
    DeleteDC(hdc2);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/116935/bitmap-speichern</link><generator>RSS for Node</generator><lastBuildDate>Fri, 03 Jul 2026 09:11:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/116935.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Aug 2005 15:20:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 15:20:49 GMT]]></title><description><![CDATA[<p>Ich habe hier eine funktion zum speichern von Bitmaps.<br />
Das Bitmap wird zwar erstellt ich kann es aber mit keinem Bildbetrachtungprogramm öffnen.</p>
<p>Was mach ich falsch?</p>
<pre><code class="language-cpp">void save(int height, int width, HDC hdc)
{
    BITMAPINFOHEADER bmih;
    BITMAPFILEHEADER bmfh;
    BITMAPINFO bi;
    HBITMAP aBmp;
    void *dibvalues;
    HGDIOBJ OldObj;
    HDC hdc2;
    DWORD bytes_write;
    DWORD bytes_written;
    HANDLE fileHandle;

    hdc2=CreateCompatibleDC(hdc);

    ZeroMemory(&amp;bmih,sizeof(BITMAPINFOHEADER));
    bmih.biSize=sizeof(BITMAPINFOHEADER);
    bmih.biHeight=height;
    bmih.biWidth=width;
    bmih.biPlanes=1;
    bmih.biBitCount=16;
    bmih.biCompression=BI_RGB; 
    bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * bmih.biHeight;
    bmih.biXPelsPerMeter = 0;
    bmih.biYPelsPerMeter = 0;
    bmih.biClrImportant = 0;

    bi.bmiHeader=bmih;

    aBmp=CreateDIBSection(hdc,&amp;bi,DIB_RGB_COLORS,(void**)&amp;dibvalues,NULL,NULL);

    OldObj=SelectObject(hdc2,aBmp);
    BitBlt(hdc2,0,0,width,height,hdc,0,0,SRCCOPY);

    ZeroMemory(&amp;bmfh,sizeof(BITMAPFILEHEADER));
    bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    bmfh.bfSize=(3*bmih.biHeight*bmih.biWidth)+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    bmfh.bfType=0x4d42;
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;

        fileHandle=CreateFile(&quot;test.bmp&quot;,GENERIC_READ | GENERIC_WRITE,(DWORD)0,NULL,
                                                    CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
    if (fileHandle==INVALID_HANDLE_VALUE)
    {
        OutputDebugString(&quot;CreateFile failed!\n&quot;);
    }

        // Write the BITMAPFILEHEADER
        bytes_write=sizeof(BITMAPFILEHEADER);
    if (!WriteFile(fileHandle,(void*)&amp;bmfh,bytes_write,&amp;bytes_written,NULL))
    {
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

        //Write the BITMAPINFOHEADER
    bytes_write=sizeof(BITMAPINFOHEADER);
    if (!WriteFile(fileHandle,(void*)&amp;bmih,bytes_write,&amp;bytes_written,NULL))
    {
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

        //Write the Color Index Array???
        bytes_write=bmih.biSizeImage;//3*bmih.biHeight*bmih.biWidth;
    if (!WriteFile(fileHandle,(void*)dibvalues,bytes_write,&amp;bytes_written,NULL))
    { 
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

    CloseHandle(fileHandle);

    DeleteObject(SelectObject(hdc2,OldObj));
    DeleteDC(hdc2);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/843656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843656</guid><dc:creator><![CDATA[Unknow]]></dc:creator><pubDate>Mon, 01 Aug 2005 15:20:49 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 16:15:43 GMT]]></title><description><![CDATA[<p>Kann mir denn Niemand helfen? Hier ich kann euch auch den gesammten code geben:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

void save(int,int,HDC);

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
     static TCHAR szAppName [] = TEXT (&quot;Stretch&quot;) ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = 0 ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL, IDI_INFORMATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;

     if (!RegisterClass (&amp;wndclass))
     {    // UNICODE-Compilierung ist die einzige realistische Fehlermöglichkeit 
          MessageBox (NULL, TEXT (&quot;Programm arbeitet mit Unicode und setzt Windows NT voraus!&quot;), 
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }

     hwnd = CreateWindow (szAppName, TEXT (&quot;StretchBlt-Demo&quot;), 
                          WS_OVERLAPPEDWINDOW, 
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, NULL) ;

     ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;

     while (GetMessage (&amp;msg, NULL, 0, 0))
     {
          TranslateMessage (&amp;msg) ;
          DispatchMessage (&amp;msg) ;
     }
     return msg.wParam ;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static int  cxClient, cyClient, cxSource, cySource ;
     HDC         hdcClient, hdcWindow ;
     HWND        hwnd2=GetDesktopWindow();
     PAINTSTRUCT ps ;

     switch (message)
     {
     case WM_CREATE:
          cxSource = GetSystemMetrics (SM_CXSCREEN);
          cySource = GetSystemMetrics (SM_CYSCREEN) ;
          return 0 ;

     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
          return 0 ;

     case WM_PAINT:
          hdcClient = BeginPaint (hwnd, &amp;ps) ;
          hdcWindow = GetWindowDC (hwnd2) ;

          StretchBlt (hdcClient, 0, 0, cxClient, cyClient,
                      hdcWindow, 0, 0, cxSource, cySource, SRCCOPY) ;

          save(cyClient,cxClient,hdcWindow);
          ReleaseDC (hwnd, hdcWindow) ;
          EndPaint (hwnd, &amp;ps) ;
          return 0 ;

     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}

void save(int height, int width, HDC hdc)
{
    BITMAPINFOHEADER bmih;
    BITMAPFILEHEADER bmfh;
    BITMAPINFO bi;
    HBITMAP aBmp;
    void *dibvalues;
    HGDIOBJ OldObj;
    HDC hdc2;
    DWORD bytes_write;
    DWORD bytes_written;
    HANDLE fileHandle;

    hdc2=CreateCompatibleDC(hdc);

    ZeroMemory(&amp;bmih,sizeof(BITMAPINFOHEADER));
    bmih.biSize=sizeof(BITMAPINFOHEADER);
    bmih.biHeight=height;
    bmih.biWidth=width;
    bmih.biPlanes=1;
    bmih.biBitCount=16;
    bmih.biCompression=BI_RGB; 
    bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * bmih.biHeight;
    bmih.biXPelsPerMeter = 0;
    bmih.biYPelsPerMeter = 0;
    bmih.biClrImportant = 0;

    bi.bmiHeader=bmih;

    aBmp=CreateDIBSection(hdc,&amp;bi,DIB_RGB_COLORS,(void**)&amp;dibvalues,NULL,NULL);

    OldObj=SelectObject(hdc2,aBmp);
    BitBlt(hdc2,0,0,width,height,hdc,0,0,SRCCOPY);

    ZeroMemory(&amp;bmfh,sizeof(BITMAPFILEHEADER));
    bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    bmfh.bfSize=(3*bmih.biHeight*bmih.biWidth)+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    bmfh.bfType=0x4d42;
    bmfh.bfReserved1 = 0;
    bmfh.bfReserved2 = 0;

        fileHandle=CreateFile(&quot;test.bmp&quot;,GENERIC_READ | GENERIC_WRITE,(DWORD)0,NULL,
                                                    CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
    if (fileHandle==INVALID_HANDLE_VALUE)
    {
        OutputDebugString(&quot;CreateFile failed!\n&quot;);
    }

        // Write the BITMAPFILEHEADER
        bytes_write=sizeof(BITMAPFILEHEADER);
    if (!WriteFile(fileHandle,(void*)&amp;bmfh,bytes_write,&amp;bytes_written,NULL))
    {
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

        //Write the BITMAPINFOHEADER
    bytes_write=sizeof(BITMAPINFOHEADER);
    if (!WriteFile(fileHandle,(void*)&amp;bmih,bytes_write,&amp;bytes_written,NULL))
    {
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

        //Write the Color Index Array???
        bytes_write=bmih.biSizeImage;//3*bmih.biHeight*bmih.biWidth;
    if (!WriteFile(fileHandle,(void*)dibvalues,bytes_write,&amp;bytes_written,NULL))
    { 
        OutputDebugString(&quot;WriteFile failed!\n&quot;);
    }

    CloseHandle(fileHandle);

    DeleteObject(SelectObject(hdc2,OldObj));
    DeleteDC(hdc2);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/843692</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843692</guid><dc:creator><![CDATA[Unknow]]></dc:creator><pubDate>Mon, 01 Aug 2005 16:15:43 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 16:59:05 GMT]]></title><description><![CDATA[<p>Der Code ist eigentlich identisch mit dem aus den FAQ, nur hast du bmih.biBitCount von 24 auf 16 abgeändert - evtl. ist das der Grund <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/843717</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843717</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Mon, 01 Aug 2005 16:59:05 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 17:01:35 GMT]]></title><description><![CDATA[<p>Leider nicht. Trotzdem schonmal danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/843720</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843720</guid><dc:creator><![CDATA[Unknow]]></dc:creator><pubDate>Mon, 01 Aug 2005 17:01:35 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 17:34:05 GMT]]></title><description><![CDATA[<p>Also bei mir wird ein bmp erzeugt, was ich dann nachher auch ohne Probleme laden kann (Paint hab ich nicht drauf, hab's aber mit IrfanView getestet)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/843736</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843736</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Mon, 01 Aug 2005 17:34:05 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 17:46:40 GMT]]></title><description><![CDATA[<p>Jetzt geht es auch bei.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/843741</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843741</guid><dc:creator><![CDATA[Unknow]]></dc:creator><pubDate>Mon, 01 Aug 2005 17:46:40 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 17:57:05 GMT]]></title><description><![CDATA[<p>Aber leider nur bei dem Compiler &quot;Visual c++ Book Edition&quot; bei &quot;Borland C++ Builder 6&quot; geht es nicht kann mir jemand dort weiterhelfen.<br />
Muss ich vielleicht eine Einstellung ändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/843746</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843746</guid><dc:creator><![CDATA[Unknow]]></dc:creator><pubDate>Mon, 01 Aug 2005 17:57:05 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Mon, 01 Aug 2005 21:15:49 GMT]]></title><description><![CDATA[<p>Evtl. dasselbe Problem wie hier ?<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-116386-and-postdays-is-0-and-postorder-is-asc-and-start-is-0.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-116386-and-postdays-is-0-and-postorder-is-asc-and-start-is-0.html</a></p>
<p>...da hat el Clio geschrieben:</p>
<p>el Clio schrieb:</p>
<blockquote>
<p>Das Problem liegt beim BCB6. Beim Byte-weisen schreiben von Strukturen hat der &quot;Kollege&quot; einen Bug, nämlich dass jede Struktur 2 Byte länger geschrieben wird, als sie ist. Wurde im Update 4 behandelt, hab ich aber nicht drauf. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /> Lässt sich aber auch über einen #pragma lösen.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/843854</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/843854</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Mon, 01 Aug 2005 21:15:49 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Thu, 04 Aug 2005 06:32:54 GMT]]></title><description><![CDATA[<p>Ich poste hier nochmal meinen funktionierenden Code. Vielleicht wäre das ganze was für die FAQ, z.B. mit dem Titel &quot;Bitmaps selbst gemacht&quot; oder so.</p>
<p>Drei Sachen sind wichtig:</p>
<p>1. bmih.biHeight darf NICHT negativ sein (obwohl die MSDN was anderes sagt), da einige Betrachtungsprogs damit nicht klar kommen und &quot;Bad Picture size&quot;-Fehler ausgeben. In der Konsequenz folgt Punkt 2.</p>
<p>2. Wegen Punkt eins müssen die Bitmapdaten (sofern benötigt) von hinten nach vorne geschrieben werden. Also das &quot;erste&quot; Pixel links oben ist im Datenarray das letzte. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
<p>3. für BCB6: wenn man nicht das Update 4 drauf hat muss man die eigenen Strukturen benutzen. Die Deklaration mit Erklärung weiter unten!</p>
<p>Der Code:</p>
<pre><code class="language-cpp">int width         = 640;
   int height        = 480;
   int bytesPerPixel = 3;  // we need 24 bit (= 3x8 bit) for 24-Bit-RGB

   // for bcb6 users (update 3 or below) only
   myBITMAPFILEHEADER bmfh;
   myBITMAPINFOHEADER bmih;

   /* the others
   BITMAPFILEHEADER bmfh;
   BITMAPINFOHEADER bmih;
   */

   BYTE *data = new BYTE[width*height*bytesPerPixel];

   bmfh.bfType       = 0x4D42; // must be &quot;BM&quot;
   bmfh.bfSize       = sizeof(bmfh) + sizeof(bmih) + sizeof(*data);
   bmfh.bfReserved1  = 0;
   bmfh.bfReserved2  = 0;
   bmfh.bfOffBits    = sizeof(bmfh) + sizeof(bmih);

   bmih.biSize          = sizeof(bmih); // self size
   bmih.biWidth         = width;
   bmih.biHeight        = height;  // negative to be a top-down-image
   bmih.biPlanes        = 1;  // must be 1
   bmih.biBitCount      = 8*bytesPerPixel; // we want a 24-bit-RGB-Image
   bmih.biCompression   = BI_RGB;   // uncompressed
   bmih.biSizeImage     = 0;  // because of BI_RGB in biCompression
   bmih.biXPelsPerMeter = 183; // pixels per meter? Microsoft...
   bmih.biYPelsPerMeter = 183; // pixels per meter? Microsoft...
   bmih.biClrUsed       = 0;  // unimportant for now
   bmih.biClrImportant  = 0;  // unimportant for now too

   for(int index = height*width*bytesPerPixel-1; index &gt; 0; index--)
   {
      switch((index%3))
      {
         // Lets make a red image
         case 2: data[index] = 255; break;   // Red; Image should be red
         case 1: data[index] = 0; break;     // Green; Image should be red
         case 0: data[index] = 0; break;     // Blue; Image should be red
      }

   }

   FILE *bmpFile = fopen(&quot;test.bmp&quot;, &quot;wb&quot;);  // open file
   if(bmpFile)
   {
      // write Bitmapfile
      fwrite(&amp;bmfh, sizeof(bmfh), 1, bmpFile);
      fwrite(&amp;bmih, sizeof(bmih), 1, bmpFile);
      fwrite(data, height*width*bytesPerPixel, 1, bmpFile);

      fclose(bmpFile); // close file
   }
</code></pre>
<p><strong>Die Strukturen</strong></p>
<p>Besagte BCB6 Benutzer ohne Update 4 werden das Problem haben, dass beim Byte-weisen schreiben Strukturen generell mit 2 Byte zuviel geschrieben werden, da aus dem Stack zuviel gepopt wird. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /><br />
Abhilfe schaffen eigene Strukturen (analog zu denen aus der MSDN) und die Befehle &quot;#pragma pack(push,1)&quot; und &quot;#pragma pack(pop)&quot;. Diese verlangsamen den Spass zwar etwas (unmerklich), beheben aber das Problem!</p>
<p>Und los:</p>
<pre><code class="language-cpp">#pragma pack(push,1)
struct myBITMAPFILEHEADER
{
  WORD    bfType;
  DWORD   bfSize;
  WORD    bfReserved1;
  WORD    bfReserved2;
  DWORD   bfOffBits;
};

struct myBITMAPINFOHEADER
{
  DWORD  biSize; 
  LONG   biWidth; 
  LONG   biHeight; 
  WORD   biPlanes; 
  WORD   biBitCount; 
  DWORD  biCompression; 
  DWORD  biSizeImage; 
  LONG   biXPelsPerMeter; 
  LONG   biYPelsPerMeter; 
  DWORD  biClrUsed; 
  DWORD  biClrImportant; 
};
#pragma pack(pop)
</code></pre>
<p>Und raus kommt ein wunderschönes Bitmap! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
<p>Hoffe, ich hab nicht zuviel Unsinn erzählt! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/845238</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/845238</guid><dc:creator><![CDATA[el Clio]]></dc:creator><pubDate>Thu, 04 Aug 2005 06:32:54 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Thu, 04 Aug 2005 11:26:36 GMT]]></title><description><![CDATA[<p>el Clio schrieb:</p>
<blockquote>
<p>2. Wegen Punkt eins müssen die Bitmapdaten (sofern benötigt) von hinten nach vorne geschrieben werden. Also das &quot;erste&quot; Pixel links oben ist im Datenarray das letzte. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
</blockquote>
<p>Die Scanlines werden von unten nach oben bearbeitet aber trotzdem noch von links nach rechts. Das Ganze ist also nicht vollständig umgedreht und deswegen ist es etwas aufwändiger als ein einfaches Rückwärtsiterieren.</p>
<p>Du hast deine Bitmapgröße übrigens immer noch fehlerhaft berechnet. Die Scanlines werden nicht an 4-Byte-Grenzen ausgerichtet und dein Algorithmus würde also bei einer Auflösung von 639x480 ein kaputtes Bitmap schreiben - probier's aus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> . Also die Bitmapgrößenberechnung folgendermaßen:</p>
<pre><code>bitmapgröße in bytes = ( (breite * bpp) + ( (breite*bpp)%32) ) ) / 8 * hoehe
</code></pre>
<p>oder bereits voroptimiert wie auch in der MSDN zu finden:</p>
<pre><code class="language-cpp">bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * bmih.biHeight;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/845485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/845485</guid><dc:creator><![CDATA[masterofx32]]></dc:creator><pubDate>Thu, 04 Aug 2005 11:26:36 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap speichern on Fri, 05 Aug 2005 14:14:37 GMT]]></title><description><![CDATA[<p>masterofx32 schrieb:</p>
<blockquote>
<p>el Clio schrieb:</p>
<blockquote>
<p>2. Wegen Punkt eins müssen die Bitmapdaten (sofern benötigt) von hinten nach vorne geschrieben werden. Also das &quot;erste&quot; Pixel links oben ist im Datenarray das letzte. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";-)"
      alt="😉"
    /></p>
</blockquote>
<p>Die Scanlines werden von unten nach oben bearbeitet aber trotzdem noch von links nach rechts. Das Ganze ist also nicht vollständig umgedreht und deswegen ist es etwas aufwändiger als ein einfaches Rückwärtsiterieren.</p>
<p>Du hast deine Bitmapgröße übrigens immer noch fehlerhaft berechnet. Die Scanlines werden nicht an 4-Byte-Grenzen ausgerichtet und dein Algorithmus würde also bei einer Auflösung von 639x480 ein kaputtes Bitmap schreiben - probier's aus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> . Also die Bitmapgrößenberechnung folgendermaßen:</p>
<pre><code>bitmapgröße in bytes = ( (breite * bpp) + ( (breite*bpp)%32) ) ) / 8 * hoehe
</code></pre>
<p>oder bereits voroptimiert wie auch in der MSDN zu finden:</p>
<pre><code class="language-cpp">bmih.biSizeImage = ((((bmih.biWidth * bmih.biBitCount) + 31) &amp; ~31) &gt;&gt; 3) * bmih.biHeight;
</code></pre>
</blockquote>
<p>Ups! Vergessen! Muss natürlich auch noch mit rein <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/846592</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/846592</guid><dc:creator><![CDATA[el Clio]]></dc:creator><pubDate>Fri, 05 Aug 2005 14:14:37 GMT</pubDate></item></channel></rss>