<?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 Rohdaten blitten?]]></title><description><![CDATA[<p>Hi,</p>
<p>Wie kann man Image-Rohdaten aus einer bmp Datei an ein HDC übergeben oder schlicht auf den Bildschirm zeichnen?</p>
<pre><code class="language-cpp">// Load bitmap file
long __stdcall LoadBitmapFile(HDC hdc, char *filename, char *data)
{
	FILE				*filePtr;			// file pointer
	BITMAPFILEHEADER	bitmapFileHeader;	// bitmap file header	
	BITMAPINFOHEADER	bitmapInfoHeader;	// bitmap info header
	unsigned char		*bitmapImage;		// bitmap image data

	unsigned long		imageIdx = 0;		// image index counter
	unsigned char		tempRGB;			// swap variable

	// open filename in &quot;read binary&quot; mode
	filePtr = fopen(filename, &quot;rb&quot;);

	if(filePtr == NULL)
	{
		MessageBox(NULL, &quot;No file&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// read the bitmap file header
	fread(&amp;bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

	// verify that this is a bitmap by checking for the univeral bitmap id
	if(bitmapFileHeader.bfType != BITMAP_ID)
	{
		fclose(filePtr);
		MessageBox(NULL, &quot;No bitmap file&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// read the bitmap information header
	fread(&amp;bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

	// move file pointer to beginning of bitmap data
	fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

	// allocate enough memory for the bitmap image data
	bitmapImage = (unsigned char*)malloc(bitmapInfoHeader.biSizeImage);

	// verify memory allocation
	if(!bitmapImage)
	{
		free(bitmapImage);
		fclose(filePtr);
		MessageBox(NULL, &quot;Memory allocation error&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// read in the bitmap image data
	fread(bitmapImage, 1, bitmapInfoHeader.biSizeImage, filePtr);

	// make sure bitmap data was read
	if(bitmapImage == NULL)
	{
		fclose(filePtr);
		MessageBox(NULL, &quot;Couldn't read bitmap data&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// swap the R and B values to get RGB since the bitmap color format is in BGR
	for(imageIdx = 0; imageIdx &lt; bitmapInfoHeader.biSizeImage; imageIdx+=3)
	{
		tempRGB = bitmapImage[imageIdx];
		bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
		bitmapImage[imageIdx + 2] = tempRGB;
	}

	// copy image data into the data parameter
	memcpy(data, bitmapImage, len);

	// blit image to hdc
	BitBlt(hdc, 0, 0, bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight, SOURCE_HDC, 0, 0, SRCCOPY);
// -&gt; Wie bekommt man die Image-Rohdaten &quot;data&quot; in ein HDC um es per BitBlt auf einen anderen HDC anzeigen zu können?

	// free memory
	free(bitmapImage);

	// close the file and return the bitmap image data
	fclose(filePtr);

	return 1;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/79147/bitmap-rohdaten-blitten</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 16:39:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/79147.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Jul 2004 12:03:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bitmap Rohdaten blitten? on Thu, 08 Jul 2004 12:03:20 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>Wie kann man Image-Rohdaten aus einer bmp Datei an ein HDC übergeben oder schlicht auf den Bildschirm zeichnen?</p>
<pre><code class="language-cpp">// Load bitmap file
long __stdcall LoadBitmapFile(HDC hdc, char *filename, char *data)
{
	FILE				*filePtr;			// file pointer
	BITMAPFILEHEADER	bitmapFileHeader;	// bitmap file header	
	BITMAPINFOHEADER	bitmapInfoHeader;	// bitmap info header
	unsigned char		*bitmapImage;		// bitmap image data

	unsigned long		imageIdx = 0;		// image index counter
	unsigned char		tempRGB;			// swap variable

	// open filename in &quot;read binary&quot; mode
	filePtr = fopen(filename, &quot;rb&quot;);

	if(filePtr == NULL)
	{
		MessageBox(NULL, &quot;No file&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// read the bitmap file header
	fread(&amp;bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

	// verify that this is a bitmap by checking for the univeral bitmap id
	if(bitmapFileHeader.bfType != BITMAP_ID)
	{
		fclose(filePtr);
		MessageBox(NULL, &quot;No bitmap file&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// read the bitmap information header
	fread(&amp;bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

	// move file pointer to beginning of bitmap data
	fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

	// allocate enough memory for the bitmap image data
	bitmapImage = (unsigned char*)malloc(bitmapInfoHeader.biSizeImage);

	// verify memory allocation
	if(!bitmapImage)
	{
		free(bitmapImage);
		fclose(filePtr);
		MessageBox(NULL, &quot;Memory allocation error&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// read in the bitmap image data
	fread(bitmapImage, 1, bitmapInfoHeader.biSizeImage, filePtr);

	// make sure bitmap data was read
	if(bitmapImage == NULL)
	{
		fclose(filePtr);
		MessageBox(NULL, &quot;Couldn't read bitmap data&quot;, &quot;Error&quot;, MB_OK);
		return 0;
	}

	// swap the R and B values to get RGB since the bitmap color format is in BGR
	for(imageIdx = 0; imageIdx &lt; bitmapInfoHeader.biSizeImage; imageIdx+=3)
	{
		tempRGB = bitmapImage[imageIdx];
		bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
		bitmapImage[imageIdx + 2] = tempRGB;
	}

	// copy image data into the data parameter
	memcpy(data, bitmapImage, len);

	// blit image to hdc
	BitBlt(hdc, 0, 0, bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight, SOURCE_HDC, 0, 0, SRCCOPY);
// -&gt; Wie bekommt man die Image-Rohdaten &quot;data&quot; in ein HDC um es per BitBlt auf einen anderen HDC anzeigen zu können?

	// free memory
	free(bitmapImage);

	// close the file and return the bitmap image data
	fclose(filePtr);

	return 1;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/555980</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/555980</guid><dc:creator><![CDATA[ble1frei]]></dc:creator><pubDate>Thu, 08 Jul 2004 12:03:20 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap Rohdaten blitten? on Thu, 08 Jul 2004 13:44:48 GMT]]></title><description><![CDATA[<p>Du willst SetDIBits oder SetDIBitsToDevice.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/556099</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/556099</guid><dc:creator><![CDATA[Ringding]]></dc:creator><pubDate>Thu, 08 Jul 2004 13:44:48 GMT</pubDate></item></channel></rss>