<?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[HBITMAP nach DIB konvertieren]]></title><description><![CDATA[<p>Wie konvertiere ich nen Bitmap in ne DIB-Section ???</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/87923/hbitmap-nach-dib-konvertieren</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 07:02:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/87923.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Oct 2004 09:11:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HBITMAP nach DIB konvertieren on Tue, 05 Oct 2004 09:11:08 GMT]]></title><description><![CDATA[<p>Wie konvertiere ich nen Bitmap in ne DIB-Section ???</p>
]]></description><link>https://www.c-plusplus.net/forum/post/621352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/621352</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Tue, 05 Oct 2004 09:11:08 GMT</pubDate></item><item><title><![CDATA[Reply to HBITMAP nach DIB konvertieren on Tue, 05 Oct 2004 11:39:38 GMT]]></title><description><![CDATA[<p>Guck mal <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_5d4g.asp" rel="nofollow">hier</a> in dem Dreh... ich erinnere mich nur dunkel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/621459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/621459</guid><dc:creator><![CDATA[nirsaja]]></dc:creator><pubDate>Tue, 05 Oct 2004 11:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to HBITMAP nach DIB konvertieren on Wed, 06 Oct 2004 14:04:46 GMT]]></title><description><![CDATA[<p>soo, hab das Ganze jetzt so gebaut :</p>
<pre><code class="language-cpp">BITMAPINFO DIB24toDIB8(HBITMAP hOldBmp24, int cx, int cy) 
{ 
   BITMAPINFO bmInfo8; 
   memset(&amp;bmInfo8,0,sizeof(BITMAPINFO)); 
   bmInfo8.bmiHeader.biSize    = sizeof(BITMAPINFOHEADER); 
   bmInfo8.bmiHeader.biWidth    = cx; 
   bmInfo8.bmiHeader.biHeight    = cy; 
   bmInfo8.bmiHeader.biPlanes    = 1; 
   bmInfo8.bmiHeader.biBitCount    = 8; 
   bmInfo8.bmiHeader.biCompression  = BI_RGB; 
   // erzeuge eine 8 bit DIB 
   BYTE *pBits8=NULL; 
   HBITMAP hBitmap8 = CreateDIBSection(NULL,&amp;bmInfo8,DIB_RGB_COLORS,(void**)&amp;pBits8,NULL,0); 

   // selectiere die 8 bit DIB in einen DC 
   HDC hDC8 = CreateCompatibleDC(NULL); 
   HGDIOBJ hOldBmp8 = SelectObject(hDC8,hBitmap8); 
   // selectiere die 24 bit DIB in nen DC 
   HDC hDC24 = CreateCompatibleDC(hDC8); 
   hOldBmp24 = (HBITMAP) SelectObject(hDC24,hOldBmp24); 

   // blite die DIB24 in die DIB8 
   // windows macht die frabraum konvertierung für dich 
   StretchBlt(hDC8,0,0,150,150,hDC24,0,0,150,150,SRCCOPY); 

  // Aufräumen 
  SelectObject(hDC24,hOldBmp24); 
  SelectObject(hDC8,hOldBmp8); 

  GetDIBits (hDC8, (HBITMAP) hOldBmp8, 0, cx, &amp;bmInfo8.bmiColors, &amp;bmInfo8, DIB_RGB_COLORS);

  DeleteDC(hDC24); 
  DeleteDC(hDC8); 

  return bmInfo8;
}
</code></pre>
<p>leider bekomme ich hierdurch einen ziemlich leeren Bereich..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/622456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/622456</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Wed, 06 Oct 2004 14:04:46 GMT</pubDate></item><item><title><![CDATA[Reply to HBITMAP nach DIB konvertieren on Wed, 06 Oct 2004 16:08:57 GMT]]></title><description><![CDATA[<p><a href="http://www.c-plusplus.net/forum/viewtopic.php?t=86750" rel="nofollow">Das hier</a> hatte aber noch funktioniert, oder?! Was genau meinst du mit dem &quot;ziemlich leeren Bereich&quot;. Wie sieht dein weiterer Code aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/622597</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/622597</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Wed, 06 Oct 2004 16:08:57 GMT</pubDate></item><item><title><![CDATA[Reply to HBITMAP nach DIB konvertieren on Thu, 07 Oct 2004 06:10:34 GMT]]></title><description><![CDATA[<p>Also die oben genannte Funktion wird von dieser hier aufgerufen :</p>
<pre><code class="language-cpp">__declspec ( dllexport ) int CALLBACK SaveClipboard(HWND hWnd, char *filename)
{
   HBITMAP B;
   BITMAPINFO bmi;
 //  BITMAPINFO *bmi;
   DEVMODE   Dev;

    /* ClipBoard laden */

    EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &amp;Dev);

   OpenClipboard(hWnd);
   B = (HBITMAP ) GetClipboardData(CF_BITMAP);
   CloseClipboard();   

   bmi = DIB24toDIB8(B, Dev.dmPelsWidth, Dev.dmPelsHeight); 

  // SaveBitmap (hBitmap, Dev.dmPelsWidth, Dev.dmPelsHeight, filename);
     write2gif(&amp;bmi, filename, true);

   DeleteObject(B);

//   ReleaseDC(hDC);
//   ReleaseDC(hDCa);
   return 0;
}
</code></pre>
<p>write2gif ist eine Funktion, die ich im netz gefunden habe und ursrünglich aus Farbdaten, die in einem Array of Char bestanden wegsichert. Die Funktion habe ich ein klein wenig umgebaut. Die Kompressionsalgorithmen zu posten würde glaub ich den Rahmen hier sprengen, aber write2gif sieht so aus :</p>
<pre><code class="language-cpp">ulong write2gif(BITMAPINFO *bmi, const char *filename, bool interlaced)
/*
  Opens a binary file of the specified name, writes the complete GIF file
  format and closes it. In case of success, returns the file size in bytes.
  Writes an interlaced GIF file if 'interlaced' is true. Parameters and 
  the image are taken from the member variables and methods of class 
  gifwriter. 

  Adapt this function to your own programming environment. Remove all
  dependencies on class gifwriter, and on Windows unless you're using
  Visual C++. The following items need to be changed - or not:
*/
{
  ulong i;
  ulong kk,clrused,datadepth;

  if(!filename)
    return 0;

FILE *f=fopen(filename,&quot;wb&quot;);  
if(!f)
  {
  MessageBox(NULL, &quot;Unable to open file:\n\r&quot;,
            &quot;Error&quot;,MB_OK);
  return 0;
  }
  ulong imagesize=bmi-&gt;bmiHeader.biSizeImage;
/*
                                                            GIF signature
*/
  fputc('G',f);
  fputc('I',f);
  fputc('F',f);
  fputc('8',f);
  fputc('7',f);
  fputc('a',f);
/*
                                                        Screen Descriptor
*/
  kk= bmi-&gt;bmiHeader.biWidth;               // Screen Width
  fputc(0xff &amp; kk , f);
  fputc((0xff00 &amp; kk) / 0x100 , f);
  kk= bmi-&gt;bmiHeader.biHeight;            // Screen Height
  fputc(0xff &amp; kk , f);
  fputc((0xff00 &amp; kk) / 0x100 , f);
  clrused=256;                   // is a power of two between 2 and 256
                                 // compute its exponent 'datadepth'
datadepth=0;                     // (between 1 and 8)        
for(i=1;i&lt;clrused;i*=2)          
  datadepth++;   

fputc(0xf0 | (0x7&amp;(datadepth-1)) , f); // write datadepth-1 to the three
                                // least significant bits of byte 5  of
                                // the Screen Descriptor
fputc(0x00 , f);                // Background color = colortable index 0 
fputc(0x00 , f);                // Byte 7 must be 0x00  
/*
                                                       Global Color Table
*/
RGBQUAD rgbq;
for(i=0; i&lt;clrused; i++)    // write 'clrused' 3-byte entries each     
  {                         // consisting of the intensity values of red,
  rgbq=bmi-&gt;bmiColors[i];   // green, blue in this order. (The colors are 
  fputc(rgbq.rgbRed , f);   // taken and converted from a Windows defined 
  fputc(rgbq.rgbGreen , f); // structure of type &quot;RGBQUAD&quot;)
  fputc(rgbq.rgbBlue , f);
  }
/*
                                                          Image Descriptor
*/  
fputc(0x2c,f);                    // Image separator character = ','
fputc(0x00,f);                    // &quot;Image Left&quot;
fputc(0x00,f);
fputc(0x00,f);                    // &quot;Image Top&quot;
fputc(0x00,f);
kk=bmi-&gt;bmiHeader.biWidth;               // Image Width
fputc(0xff &amp; kk , f);             // (low byte first)
fputc((0xff00 &amp; kk) / 0x100 , f);
kk=bmi-&gt;bmiHeader.biHeight;              // Image Height
fputc(0xff &amp; kk , f);
fputc((0xff00 &amp; kk) / 0x100 , f);

kk=interlaced ? 0x40 : 0x00;    // Byte 10 contains the interlaced flag and
fputc(kk|(0x7 &amp; (datadepth-1)),f); // information on the local color table.
                                   // There is no local color table if its
                                   // most significant bit is reset.
ulong filesize=6 + 7 + 3*256 + 10;
/*
                                                               &quot;Raster Data&quot;
*/
gifcompressor *gc=new gifcompressor;
if(gc)
  filesize += gc-&gt;writedatablocks( f
                                 , (unsigned char *)bmi-&gt;bmiColors
                                 , imagesize,bmi-&gt;bmiHeader.biWidth
                                 , datadepth,
                                   interlaced
                                 );
delete gc;
/*
                                                              GIF terminator
*/
fputc(0x3b,f);   // tells the decoder software to return
                 // to its calling environment
fclose(f);
return filesize+1;
} // write2gif
</code></pre>
<p>Ich möchte hiermit einen Screenshot als GIF wegsichern. (hab um die GDI+ gebeten, die wird aber in der Firma bis auf weiteres verboten, da sie der Grund für den JPEG-Virus war) Das Ergebnis ist aber immer ein weißes GIF mit 1280 * 1024 Pixeln (wobei die Auflösung korrekt ist, aber mein Bildschirm ist nicht weiß..)</p>
<p>Edit: hab die Funktion <a href="http://members.aol.com/rf21exe/gif.htm" rel="nofollow">hier</a> gefunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/622758</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/622758</guid><dc:creator><![CDATA[DocJunioR]]></dc:creator><pubDate>Thu, 07 Oct 2004 06:10:34 GMT</pubDate></item></channel></rss>