<?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 einlesen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hab von diesem Thema schon viele Posts gelesen, doch keines hat mir weitergeholfgen, desshalb mache ich einen neuen auf.</p>
<p>Ich möchte ein Bitmap in eine Matrix einlesen, aber irgentetwas muss ich falsch machen, denn das eingelesene Bild ist verschoben.</p>
<p>Ursprungsbild:<br />
|----------|</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Hallo</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p>Bild nach dem Einlesen</p>
<p>|----------|</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>lloHa</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p>Komplette Teile des Bildes werden verschoben.</p>
<p>Hier mein Code:</p>
<pre><code>ifstream testsize(&quot;c:\\jan24.bmp&quot;, ios::ate);
	if(testsize.is_open())
	{		
		BYTE * Pic = new BYTE[testsize.tellg()];		
		testsize.close();
		ifstream s;
		BITMAPFILEHEADER *h1;
		BITMAPINFOHEADER *h2;
		int i = 0;
		s.open(&quot;c:\\jan24.bmp&quot;);
		if(s.is_open() )
		{
			i = 0;
			//datei in array schreiben
			while(! s.eof())
				Pic[i++] = s.get();

			h1 = ( BITMAPFILEHEADER *) Pic;
			h2 = ( BITMAPINFOHEADER *) (Pic + sizeof(BITMAPFILEHEADER));	
			int x = 0, y = h2-&gt;biHeight;

			for(int j = h1-&gt;bfOffBits + sizeof(BITMAPFILEHEADER); j &lt; i; j += (h2-&gt;biBitCount/8))
			{
				if(j % h2-&gt;biWidth == 0) // neue Zeile?
				{
					x = 0;
					y--;
				}
				else
					x++;	

				//Zum testen die punkte ausgeben
				pDC-&gt;SetPixel(x,y, Pic[j]);
			}

		}
	}
</code></pre>
<p>Was mache ich falsch?</p>
<p>Gruß Stu</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/138840/bitmap-einlesen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 03:40:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/138840.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 01 Mar 2006 18:43:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bitmap einlesen on Wed, 01 Mar 2006 18:43:13 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich hab von diesem Thema schon viele Posts gelesen, doch keines hat mir weitergeholfgen, desshalb mache ich einen neuen auf.</p>
<p>Ich möchte ein Bitmap in eine Matrix einlesen, aber irgentetwas muss ich falsch machen, denn das eingelesene Bild ist verschoben.</p>
<p>Ursprungsbild:<br />
|----------|</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Hallo</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p>Bild nach dem Einlesen</p>
<p>|----------|</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>lloHa</th>
</tr>
</thead>
<tbody></tbody>
</table>
<p>Komplette Teile des Bildes werden verschoben.</p>
<p>Hier mein Code:</p>
<pre><code>ifstream testsize(&quot;c:\\jan24.bmp&quot;, ios::ate);
	if(testsize.is_open())
	{		
		BYTE * Pic = new BYTE[testsize.tellg()];		
		testsize.close();
		ifstream s;
		BITMAPFILEHEADER *h1;
		BITMAPINFOHEADER *h2;
		int i = 0;
		s.open(&quot;c:\\jan24.bmp&quot;);
		if(s.is_open() )
		{
			i = 0;
			//datei in array schreiben
			while(! s.eof())
				Pic[i++] = s.get();

			h1 = ( BITMAPFILEHEADER *) Pic;
			h2 = ( BITMAPINFOHEADER *) (Pic + sizeof(BITMAPFILEHEADER));	
			int x = 0, y = h2-&gt;biHeight;

			for(int j = h1-&gt;bfOffBits + sizeof(BITMAPFILEHEADER); j &lt; i; j += (h2-&gt;biBitCount/8))
			{
				if(j % h2-&gt;biWidth == 0) // neue Zeile?
				{
					x = 0;
					y--;
				}
				else
					x++;	

				//Zum testen die punkte ausgeben
				pDC-&gt;SetPixel(x,y, Pic[j]);
			}

		}
	}
</code></pre>
<p>Was mache ich falsch?</p>
<p>Gruß Stu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006138</guid><dc:creator><![CDATA[Stu]]></dc:creator><pubDate>Wed, 01 Mar 2006 18:43:13 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap einlesen on Thu, 02 Mar 2006 07:56:09 GMT]]></title><description><![CDATA[<p>Erstmal ist es nicht nötig, das File zwischendurch wieder zu schließen und neu zu öffnen - du kannst auch einfach mit seekg(0) an den Dateianfang springen.</p>
<p>Und zweitens berechnest du den Start des Bildbereiches falsch - 'h1-&gt;bfOffBits' ist bereits der Index des ersten Pixels</p>
<p>MSDN schrieb:</p>
<blockquote>
<p><strong>bfOffBits</strong><br />
Specifies the offset, in bytes, from the beginning of the BITMAPFILEHEADER structure to the bitmap bits.</p>
</blockquote>
<p>(das bewirkt eine Verschiebung deines Bildes um *rechnet* ca. 14 Byte)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006410</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006410</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 02 Mar 2006 07:56:09 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap einlesen on Thu, 02 Mar 2006 13:45:08 GMT]]></title><description><![CDATA[<p>ah vielen dank, ich hab zwar noch eine verschiebung, aber die ist deutlich kleiner. Jetz wo ich weiß woran es liegt, werd ich es schon richtig schaffen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006811</guid><dc:creator><![CDATA[Stu]]></dc:creator><pubDate>Thu, 02 Mar 2006 13:45:08 GMT</pubDate></item><item><title><![CDATA[Reply to Bitmap einlesen on Thu, 02 Mar 2006 16:18:47 GMT]]></title><description><![CDATA[<p>ich bin nochmal <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>das Bilder einlesen klappt ziehlich gut. Ich Benutze folgenden Algorythmus:</p>
<pre><code>ifstream bitmap(&quot;c:\\t.bmp&quot;, ios::ate);
	BYTE* Pic;
	if(bitmap.is_open())
	{		
		Pic = new BYTE[bitmap.tellg()];		
		bitmap.seekg(0);
		BITMAPFILEHEADER *h1;
		BITMAPINFOHEADER *h2;
		int i = 0;
		i = 0;
		//datei in array schreiben
		while(! bitmap.eof())
			Pic[i++] = bitmap.get();

		h1 = ( BITMAPFILEHEADER *) Pic;
		h2 = ( BITMAPINFOHEADER *) (Pic + sizeof(BITMAPFILEHEADER));	
		DWORD col;
		if(h2-&gt;biBitCount == 24) //nur 16bit bitmaps lesen
			for(int b = 0,c = h2-&gt;biHeight-1; b &lt;h2-&gt;biHeight; b++,c--)
				for(int a = 0; a &lt; h2-&gt;biWidth; a++)
				{
					BYTE * color = (BYTE* ) (Pic + ((a + (b*h2-&gt;biWidth))*(h2-&gt;biBitCount/8)) +  h1-&gt;bfOffBits );
					col = 0;
					col |= *(color);
					col &lt;&lt;=8;
					col |= *(color+1);
					col &lt;&lt;=8;
					col |= *(color+2);
					pDC-&gt;SetPixel(a,c,col);

				}	

		//delete[] Pic;
	}
</code></pre>
<p>Nun habe ich aber folgendes problem.<br />
Wenn ich ein normales Bitmap nehme, also eines wo ich selbst ein bischen gezeichnet hab, dann wird das Bild richtig angezeigt. Aber sobald ich z.B. nen Screenshot nehme, macht er alles Grau, nur am ende des Bildes sind ein paar Bildausschnitte.</p>
<p>Wie kann das sein das alles grau wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1006991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1006991</guid><dc:creator><![CDATA[Stu]]></dc:creator><pubDate>Thu, 02 Mar 2006 16:18:47 GMT</pubDate></item></channel></rss>