<?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 speichern als ppm]]></title><description><![CDATA[<p>Hallo cpp'ler,</p>
<p>ich hänge an dem Problem, dass ich einen Screenshot vom derzeitigen Desktop machen und den dann in einem Bild (nämlich einer ppm (p6)) speichern möchte.</p>
<p>Dank vielen lesens bin ich nun hier:</p>
<pre><code class="language-cpp">Image Input::getScreenShot(){
	 // Handle to device context. If this value is NULL, GetDC retrieves the DC for the entire screen.
	 HDC deviceContext = ::GetDC(desktopWindow);

	 // Create BITMAPINFO structure used by CreateDIBSection
	 BITMAPINFO info				= {0};
	 info.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
	 info.bmiHeader.biWidth         = screenWidth;
	 info.bmiHeader.biHeight        = screenHeight;
	 info.bmiHeader.biPlanes        = 1;
	 info.bmiHeader.biBitCount      = 32;

	 // A bitmap handle and a pointer its bit data
	 HBITMAP bitmap = 0;
	 RGBQUAD* memory = 0;

	 /*
	  * The CreateDIBSection function creates a DIB that applications can write to directly.
	  * The function gives you a pointer to the location of the bitmap bit values. You can
	  * supply a handle to a file-mapping object that the function will use to create the bitmap,
	  * or you can let the system allocate the memory for the bitmap.
	  */
	 bitmap = CreateDIBSection(deviceContext, &amp;info, DIB_RGB_COLORS, (void**)&amp;memory,0, 0);
	 //This function releases a device context, freeing it for use by other applications.
	 ReleaseDC(desktopWindow, deviceContext);

	 /**
	  * Blit the contents of the desktop (winDC) to the bitmap (selected in memDC).
	  *
	  * &quot;blit&quot; bedeutet einen (rechteckigen) Block in einem Grafikspeicher an eine andere
	  * Position in diesem Speicher oder manchmal einem andern Speicher zu verschieben.
	  */
	 HDC winDC = GetWindowDC(desktopWindow);

	 // This function creates a memory device context (DC) compatible with the specified device.
	 HDC memDC = CreateCompatibleDC(winDC);

	 // This function selects an object into a specified device context.
	 SelectObject(memDC, bitmap);

	 /**
	  * This function transfers pixels from a specified source rectangle to a specified destination
	  * rectangle, altering the pixels according to the selected raster operation (ROP) code.
	  */
	 BitBlt(memDC, 0, 0, screenWidth, screenHeight, winDC, 0, 0, SRCCOPY);

	 // The DeleteDC function deletes the specified device context (DC).
	 //DeleteDC(memDC);

	 //This function releases a device context, freeing it for use by other applications.
	 // ReleaseDC(desktopWindow, winDC);

	 cout&lt;&lt;&quot;P6 1680 1050 255\n&quot;;
	 int offset=0;
	 unsigned int i=screenWidth*screenHeight;

	 for (unsigned int y=1; y&lt;=screenHeight; y++){

		 offset=(y*screenWidth);
		 for (unsigned int x=0; x&lt;screenWidth; x++){
			 RGBQUAD *p = &amp;memory[i-offset];			
			 cout&lt;&lt;p-&gt;rgbRed&lt;&lt;p-&gt;rgbGreen&lt;&lt;p-&gt;rgbBlue;
			 offset--;
		 }
	 }

	 // delete bitmap
	 DeleteObject(bitmap);
}
</code></pre>
<p>Wenn ich nun .exe &gt; text.ppm aufrufe (die natürlich die funktion nutzt), bekomme ich zwar ein richtig gedrehtes Bild, aber die die Pixel sind irgendwie.... kaputt...</p>
<p>sample (5mb): <a href="http://christoph.mytanet.de/screenshot.ppm" rel="nofollow">http://christoph.mytanet.de/screenshot.ppm</a></p>
<p>Danke im vorraus.</p>
<p>Christoph</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/238608/screenshot-speichern-als-ppm</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 22:04:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/238608.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Apr 2009 09:29:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Screenshot speichern als ppm on Mon, 13 Apr 2009 09:29:54 GMT]]></title><description><![CDATA[<p>Hallo cpp'ler,</p>
<p>ich hänge an dem Problem, dass ich einen Screenshot vom derzeitigen Desktop machen und den dann in einem Bild (nämlich einer ppm (p6)) speichern möchte.</p>
<p>Dank vielen lesens bin ich nun hier:</p>
<pre><code class="language-cpp">Image Input::getScreenShot(){
	 // Handle to device context. If this value is NULL, GetDC retrieves the DC for the entire screen.
	 HDC deviceContext = ::GetDC(desktopWindow);

	 // Create BITMAPINFO structure used by CreateDIBSection
	 BITMAPINFO info				= {0};
	 info.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
	 info.bmiHeader.biWidth         = screenWidth;
	 info.bmiHeader.biHeight        = screenHeight;
	 info.bmiHeader.biPlanes        = 1;
	 info.bmiHeader.biBitCount      = 32;

	 // A bitmap handle and a pointer its bit data
	 HBITMAP bitmap = 0;
	 RGBQUAD* memory = 0;

	 /*
	  * The CreateDIBSection function creates a DIB that applications can write to directly.
	  * The function gives you a pointer to the location of the bitmap bit values. You can
	  * supply a handle to a file-mapping object that the function will use to create the bitmap,
	  * or you can let the system allocate the memory for the bitmap.
	  */
	 bitmap = CreateDIBSection(deviceContext, &amp;info, DIB_RGB_COLORS, (void**)&amp;memory,0, 0);
	 //This function releases a device context, freeing it for use by other applications.
	 ReleaseDC(desktopWindow, deviceContext);

	 /**
	  * Blit the contents of the desktop (winDC) to the bitmap (selected in memDC).
	  *
	  * &quot;blit&quot; bedeutet einen (rechteckigen) Block in einem Grafikspeicher an eine andere
	  * Position in diesem Speicher oder manchmal einem andern Speicher zu verschieben.
	  */
	 HDC winDC = GetWindowDC(desktopWindow);

	 // This function creates a memory device context (DC) compatible with the specified device.
	 HDC memDC = CreateCompatibleDC(winDC);

	 // This function selects an object into a specified device context.
	 SelectObject(memDC, bitmap);

	 /**
	  * This function transfers pixels from a specified source rectangle to a specified destination
	  * rectangle, altering the pixels according to the selected raster operation (ROP) code.
	  */
	 BitBlt(memDC, 0, 0, screenWidth, screenHeight, winDC, 0, 0, SRCCOPY);

	 // The DeleteDC function deletes the specified device context (DC).
	 //DeleteDC(memDC);

	 //This function releases a device context, freeing it for use by other applications.
	 // ReleaseDC(desktopWindow, winDC);

	 cout&lt;&lt;&quot;P6 1680 1050 255\n&quot;;
	 int offset=0;
	 unsigned int i=screenWidth*screenHeight;

	 for (unsigned int y=1; y&lt;=screenHeight; y++){

		 offset=(y*screenWidth);
		 for (unsigned int x=0; x&lt;screenWidth; x++){
			 RGBQUAD *p = &amp;memory[i-offset];			
			 cout&lt;&lt;p-&gt;rgbRed&lt;&lt;p-&gt;rgbGreen&lt;&lt;p-&gt;rgbBlue;
			 offset--;
		 }
	 }

	 // delete bitmap
	 DeleteObject(bitmap);
}
</code></pre>
<p>Wenn ich nun .exe &gt; text.ppm aufrufe (die natürlich die funktion nutzt), bekomme ich zwar ein richtig gedrehtes Bild, aber die die Pixel sind irgendwie.... kaputt...</p>
<p>sample (5mb): <a href="http://christoph.mytanet.de/screenshot.ppm" rel="nofollow">http://christoph.mytanet.de/screenshot.ppm</a></p>
<p>Danke im vorraus.</p>
<p>Christoph</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1695151</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1695151</guid><dc:creator><![CDATA[ChristophT]]></dc:creator><pubDate>Mon, 13 Apr 2009 09:29:54 GMT</pubDate></item><item><title><![CDATA[Reply to Screenshot speichern als ppm on Mon, 13 Apr 2009 18:10:43 GMT]]></title><description><![CDATA[<p>Fehler gefunden. Windows speichert für jedes \n ein \r\t und das macht alles kaputt. Also einfach den outputstream auf binary stellen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1695325</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1695325</guid><dc:creator><![CDATA[ChristophT]]></dc:creator><pubDate>Mon, 13 Apr 2009 18:10:43 GMT</pubDate></item></channel></rss>