<?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[Screenshot in kleine Datei speichern]]></title><description><![CDATA[<p>Hallo zusammen, ich habe folgenden Code, um einen Screenshot zu erstellen:</p>
<pre><code>#include &lt;windows.h&gt; 
#include &lt;string&gt; 
#include &lt;iostream&gt; 

#pragma comment(lib, &quot;Gdi32.lib&quot;)

using namespace std; 

class CStellwerk 
{ 
private: 
    HWND m_hDesktop; 
public: 

    void MakeScreenshot(char SavePath[]); 
    void SaveScreen(HWND pScreen, char Path[]); 
}; 

void CStellwerk::MakeScreenshot(char SavePath[]) 
{ 
     m_hDesktop =  GetDesktopWindow(); 
     if(m_hDesktop == NULL) 
     { 
         exit(1); 
     } 
     SaveScreen(m_hDesktop,SavePath); 
} 

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow) 
{ 
    CStellwerk Stellwerk; 
    Stellwerk.MakeScreenshot(&quot;screen.bmp&quot;); 

} 

void CStellwerk::SaveScreen(HWND pScreen, char Path[]) 
{ 
int     nWidth  = GetSystemMetrics(SM_CXSCREEN); 
int     nHeight = GetSystemMetrics(SM_CYSCREEN);
char acUserName[100]; 

HWND    hWnd    = ::GetDesktopWindow(); 
HDC     hdc     = ::GetDC(hWnd); 
HDC     memDC   = ::CreateCompatibleDC(hdc); 
HBITMAP hbm     = ::CreateCompatibleBitmap(hdc, nWidth, nHeight); 
HBITMAP hbmOld  = (HBITMAP)::SelectObject(memDC, hbm); 

::BitBlt(memDC, 0, 0, nWidth, nHeight, hdc, 0, 0, SRCCOPY); 

BITMAPINFO bmi; 

ZeroMemory(&amp;bmi, sizeof(bmi)); 

bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER); 
bmi.bmiHeader.biWidth        = nWidth; 
bmi.bmiHeader.biHeight       = nHeight; 
bmi.bmiHeader.biBitCount     = 24; 
bmi.bmiHeader.biPlanes       = 1; 
bmi.bmiHeader.biCompression  = BI_RGB; 
bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biBitCount * nWidth * nHeight / 8; 

BYTE *pbBits = new BYTE[bmi.bmiHeader.biSizeImage]; 

::GetDIBits( memDC, 
             hbm, 
             0, 
             bmi.bmiHeader.biHeight, 
             pbBits, 
             &amp;bmi, 
             DIB_RGB_COLORS ); 

BITMAPFILEHEADER bfh; 

bfh.bfType      = ('M' &lt;&lt; 8) + 'B'; 
bfh.bfSize      = sizeof(BITMAPFILEHEADER)  + 
                  bmi.bmiHeader.biSizeImage + 
                  sizeof(BITMAPINFOHEADER); 
bfh.bfReserved1 = 0; 
bfh.bfReserved2 = 0; 
bfh.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 
// 
//  Hier: 
// 

DWORD nUserName = sizeof(acUserName);
if (GetUserName(acUserName, &amp;nUserName)){}

HANDLE hfile = CreateFile( &quot;screen.bmp&quot;,  //TEXT(acUserName), // UM DIESE ZEILE GEHT ES! 
                           GENERIC_WRITE, 
                           0, 
                           0, 
                           OPEN_ALWAYS, 
                           0, 
                           0 ); 

DWORD dwWritten; 

WriteFile(hfile,&amp;bfh,           sizeof(bfh),               &amp;dwWritten, NULL); 
WriteFile(hfile,&amp;bmi.bmiHeader, sizeof(BITMAPINFOHEADER),  &amp;dwWritten, NULL); 
WriteFile(hfile,pbBits,         bmi.bmiHeader.biSizeImage, &amp;dwWritten, NULL); 

CloseHandle(hfile); 

::SelectObject(memDC, hbmOld); 
::DeleteDC(memDC); 
::ReleaseDC(hWnd,hdc); 
::DeleteObject(hbm); 

delete[] pbBits; 
}
</code></pre>
<p>Das Problem das ich habe: die erstellte Datei mit dem Screenshot ist 4MB groß.</p>
<p>Wie mache ich den Screenshot so, dass er in eine kleine Datei gespeichert wird. Sprich wie beeinflusse ich die Dateigröße der bitmap....?</p>
<p>Danke im Voraus!</p>
<p>edurne</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/237804/screenshot-in-kleine-datei-speichern</link><generator>RSS for Node</generator><lastBuildDate>Wed, 23 Sep 2026 09:33:49 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/237804.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Apr 2009 07:34:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Screenshot in kleine Datei speichern on Thu, 02 Apr 2009 07:34:10 GMT]]></title><description><![CDATA[<p>Hallo zusammen, ich habe folgenden Code, um einen Screenshot zu erstellen:</p>
<pre><code>#include &lt;windows.h&gt; 
#include &lt;string&gt; 
#include &lt;iostream&gt; 

#pragma comment(lib, &quot;Gdi32.lib&quot;)

using namespace std; 

class CStellwerk 
{ 
private: 
    HWND m_hDesktop; 
public: 

    void MakeScreenshot(char SavePath[]); 
    void SaveScreen(HWND pScreen, char Path[]); 
}; 

void CStellwerk::MakeScreenshot(char SavePath[]) 
{ 
     m_hDesktop =  GetDesktopWindow(); 
     if(m_hDesktop == NULL) 
     { 
         exit(1); 
     } 
     SaveScreen(m_hDesktop,SavePath); 
} 

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow) 
{ 
    CStellwerk Stellwerk; 
    Stellwerk.MakeScreenshot(&quot;screen.bmp&quot;); 

} 

void CStellwerk::SaveScreen(HWND pScreen, char Path[]) 
{ 
int     nWidth  = GetSystemMetrics(SM_CXSCREEN); 
int     nHeight = GetSystemMetrics(SM_CYSCREEN);
char acUserName[100]; 

HWND    hWnd    = ::GetDesktopWindow(); 
HDC     hdc     = ::GetDC(hWnd); 
HDC     memDC   = ::CreateCompatibleDC(hdc); 
HBITMAP hbm     = ::CreateCompatibleBitmap(hdc, nWidth, nHeight); 
HBITMAP hbmOld  = (HBITMAP)::SelectObject(memDC, hbm); 

::BitBlt(memDC, 0, 0, nWidth, nHeight, hdc, 0, 0, SRCCOPY); 

BITMAPINFO bmi; 

ZeroMemory(&amp;bmi, sizeof(bmi)); 

bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER); 
bmi.bmiHeader.biWidth        = nWidth; 
bmi.bmiHeader.biHeight       = nHeight; 
bmi.bmiHeader.biBitCount     = 24; 
bmi.bmiHeader.biPlanes       = 1; 
bmi.bmiHeader.biCompression  = BI_RGB; 
bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biBitCount * nWidth * nHeight / 8; 

BYTE *pbBits = new BYTE[bmi.bmiHeader.biSizeImage]; 

::GetDIBits( memDC, 
             hbm, 
             0, 
             bmi.bmiHeader.biHeight, 
             pbBits, 
             &amp;bmi, 
             DIB_RGB_COLORS ); 

BITMAPFILEHEADER bfh; 

bfh.bfType      = ('M' &lt;&lt; 8) + 'B'; 
bfh.bfSize      = sizeof(BITMAPFILEHEADER)  + 
                  bmi.bmiHeader.biSizeImage + 
                  sizeof(BITMAPINFOHEADER); 
bfh.bfReserved1 = 0; 
bfh.bfReserved2 = 0; 
bfh.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); 
// 
//  Hier: 
// 

DWORD nUserName = sizeof(acUserName);
if (GetUserName(acUserName, &amp;nUserName)){}

HANDLE hfile = CreateFile( &quot;screen.bmp&quot;,  //TEXT(acUserName), // UM DIESE ZEILE GEHT ES! 
                           GENERIC_WRITE, 
                           0, 
                           0, 
                           OPEN_ALWAYS, 
                           0, 
                           0 ); 

DWORD dwWritten; 

WriteFile(hfile,&amp;bfh,           sizeof(bfh),               &amp;dwWritten, NULL); 
WriteFile(hfile,&amp;bmi.bmiHeader, sizeof(BITMAPINFOHEADER),  &amp;dwWritten, NULL); 
WriteFile(hfile,pbBits,         bmi.bmiHeader.biSizeImage, &amp;dwWritten, NULL); 

CloseHandle(hfile); 

::SelectObject(memDC, hbmOld); 
::DeleteDC(memDC); 
::ReleaseDC(hWnd,hdc); 
::DeleteObject(hbm); 

delete[] pbBits; 
}
</code></pre>
<p>Das Problem das ich habe: die erstellte Datei mit dem Screenshot ist 4MB groß.</p>
<p>Wie mache ich den Screenshot so, dass er in eine kleine Datei gespeichert wird. Sprich wie beeinflusse ich die Dateigröße der bitmap....?</p>
<p>Danke im Voraus!</p>
<p>edurne</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689660</guid><dc:creator><![CDATA[edurne]]></dc:creator><pubDate>Thu, 02 Apr 2009 07:34:10 GMT</pubDate></item><item><title><![CDATA[Reply to Screenshot in kleine Datei speichern on Thu, 02 Apr 2009 07:49:30 GMT]]></title><description><![CDATA[<p>Ich würde mir eine Grafik-Lib organisieren und dann direkt ein jpg oder png draus machen.. also ein Bildformat mit Kompression...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689665</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689665</guid><dc:creator><![CDATA[Machine]]></dc:creator><pubDate>Thu, 02 Apr 2009 07:49:30 GMT</pubDate></item><item><title><![CDATA[Reply to Screenshot in kleine Datei speichern on Thu, 02 Apr 2009 07:50:02 GMT]]></title><description><![CDATA[<p>du speicherst es als jpg(verlustbehaftet) oder png(verlustfrei).<br />
alternativ kannst du natürlich auch das bild einfach runterskalieren, oder den bereich, den du haben willst ausschneiden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689667</guid><dc:creator><![CDATA[Krux]]></dc:creator><pubDate>Thu, 02 Apr 2009 07:50:02 GMT</pubDate></item><item><title><![CDATA[Reply to Screenshot in kleine Datei speichern on Thu, 02 Apr 2009 08:06:40 GMT]]></title><description><![CDATA[<p>wie würde ich die Graphik herunterskalieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689678</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689678</guid><dc:creator><![CDATA[edurne]]></dc:creator><pubDate>Thu, 02 Apr 2009 08:06:40 GMT</pubDate></item><item><title><![CDATA[Reply to Screenshot in kleine Datei speichern on Thu, 02 Apr 2009 08:13:01 GMT]]></title><description><![CDATA[<p>Zum Beispiel kannst du statt BitBlt StretchBlt benutzen (damit kannst du auch strecken/stauchen). Dann nimmst du versuchsweise einfach ein Viertel der Originalgröße (halbe Breite, halbe Höhe) und hast so eine deutlich kleinere Datei.</p>
<p>EDIT: Aber wenn es nur um die Größer der Datei geht, ist eine Kompression vielleicht sinnvoller...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689681</guid><dc:creator><![CDATA[_matze]]></dc:creator><pubDate>Thu, 02 Apr 2009 08:13:01 GMT</pubDate></item><item><title><![CDATA[Reply to Screenshot in kleine Datei speichern on Thu, 02 Apr 2009 08:16:14 GMT]]></title><description><![CDATA[<p>ok verstanden...und für die Kompression brauche ich extra libs richtig?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1689686</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1689686</guid><dc:creator><![CDATA[edurne]]></dc:creator><pubDate>Thu, 02 Apr 2009 08:16:14 GMT</pubDate></item></channel></rss>