<?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[PNG Bild in Byte-Array ?]]></title><description><![CDATA[<p>Hi!</p>
<p>Kann mir jemand hier sagen, wie ich eine PNG-Bild Datei, in ein Byte-Array laden kann?<br />
Mit einem BMP File hab ich es nach (etwas längerer Zeit :)) geschafft:</p>
<pre><code class="language-cpp">BYTE* LoadBMP ( int* width, int* height, long* size, long* depth, char* bmpfile )
{
	/* bitmap structures */
	BITMAPFILEHEADER bmpheader;
	BITMAPINFOHEADER bmpinfo;
	DWORD bytesread;

	/* open input file */
	HANDLE file = CreateFile ( bmpfile , GENERIC_READ, FILE_SHARE_READ,
		 NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
	if ( NULL == file )
		return NULL; // coudn't open file

	/* read file header */
	if ( ReadFile ( file, &amp;bmpheader, sizeof ( BITMAPFILEHEADER ), &amp;bytesread, NULL ) == false )
	{
		CloseHandle ( file );
		return NULL;
	}

	if ( ReadFile ( file, &amp;bmpinfo, sizeof ( BITMAPINFOHEADER ), &amp;bytesread, NULL ) == false )
	{
		CloseHandle ( file );
		return NULL;
	}

	/* und hier fliegt er bei nem PNG raus */
	if ( bmpheader.bfType != 'MB' )
	{
		printf(&quot;not a bitmap!\n&quot;);
		CloseHandle ( file );
		return NULL;
	}

	/* image size */
	*width   = bmpinfo.biWidth;
	*height  = abs ( bmpinfo.biHeight );

	*depth = bmpinfo.biBitCount;
	*size = bmpheader.bfSize - bmpheader.bfOffBits;
	BYTE* Buffer = new BYTE[ *size ];
	SetFilePointer ( file, bmpheader.bfOffBits, NULL, FILE_BEGIN );
	if ( ReadFile ( file, Buffer, *size, &amp;bytesread, NULL ) == false )
	{
		printf(&quot;unable to stat ReadFile()\n&quot;);
		delete [] Buffer;
		CloseHandle ( file );
		return NULL;
	}
	CloseHandle ( file );

	return Buffer;
}
</code></pre>
<p>hat jemand nen kleinen Tip ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/107566/png-bild-in-byte-array</link><generator>RSS for Node</generator><lastBuildDate>Tue, 30 Jun 2026 02:14:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/107566.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 20 Apr 2005 17:56:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to PNG Bild in Byte-Array ? on Wed, 20 Apr 2005 17:56:33 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Kann mir jemand hier sagen, wie ich eine PNG-Bild Datei, in ein Byte-Array laden kann?<br />
Mit einem BMP File hab ich es nach (etwas längerer Zeit :)) geschafft:</p>
<pre><code class="language-cpp">BYTE* LoadBMP ( int* width, int* height, long* size, long* depth, char* bmpfile )
{
	/* bitmap structures */
	BITMAPFILEHEADER bmpheader;
	BITMAPINFOHEADER bmpinfo;
	DWORD bytesread;

	/* open input file */
	HANDLE file = CreateFile ( bmpfile , GENERIC_READ, FILE_SHARE_READ,
		 NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL );
	if ( NULL == file )
		return NULL; // coudn't open file

	/* read file header */
	if ( ReadFile ( file, &amp;bmpheader, sizeof ( BITMAPFILEHEADER ), &amp;bytesread, NULL ) == false )
	{
		CloseHandle ( file );
		return NULL;
	}

	if ( ReadFile ( file, &amp;bmpinfo, sizeof ( BITMAPINFOHEADER ), &amp;bytesread, NULL ) == false )
	{
		CloseHandle ( file );
		return NULL;
	}

	/* und hier fliegt er bei nem PNG raus */
	if ( bmpheader.bfType != 'MB' )
	{
		printf(&quot;not a bitmap!\n&quot;);
		CloseHandle ( file );
		return NULL;
	}

	/* image size */
	*width   = bmpinfo.biWidth;
	*height  = abs ( bmpinfo.biHeight );

	*depth = bmpinfo.biBitCount;
	*size = bmpheader.bfSize - bmpheader.bfOffBits;
	BYTE* Buffer = new BYTE[ *size ];
	SetFilePointer ( file, bmpheader.bfOffBits, NULL, FILE_BEGIN );
	if ( ReadFile ( file, Buffer, *size, &amp;bytesread, NULL ) == false )
	{
		printf(&quot;unable to stat ReadFile()\n&quot;);
		delete [] Buffer;
		CloseHandle ( file );
		return NULL;
	}
	CloseHandle ( file );

	return Buffer;
}
</code></pre>
<p>hat jemand nen kleinen Tip ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771540</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771540</guid><dc:creator><![CDATA[DingsBums]]></dc:creator><pubDate>Wed, 20 Apr 2005 17:56:33 GMT</pubDate></item><item><title><![CDATA[Reply to PNG Bild in Byte-Array ? on Wed, 20 Apr 2005 18:08:09 GMT]]></title><description><![CDATA[<p>Eine PNG-Datei ist keine BMP-Datei. Letztere hat eine eindeutige Dateistruktur und man kann jedes Pixel direkt über ein BYTE-Array ansprechen.</p>
<p>Informationen findest Du hier (sogar in deutsch):<br />
<a href="http://stud3.tuwien.ac.at/~e9925208/ping.htm" rel="nofollow">http://stud3.tuwien.ac.at/~e9925208/ping.htm</a><br />
<a href="http://de.wikipedia.org/wiki/Portable_Network_Graphics#Technische_Details" rel="nofollow">http://de.wikipedia.org/wiki/Portable_Network_Graphics#Technische_Details</a></p>
<p>Ich nehme mal an, das Du auch irgendwas mit dem Array anstellen willst. Dann ist wohl die Konvertierung in BMP die einfachere Lösung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771549</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771549</guid><dc:creator><![CDATA[Manfred Schmidtke]]></dc:creator><pubDate>Wed, 20 Apr 2005 18:08:09 GMT</pubDate></item><item><title><![CDATA[Reply to PNG Bild in Byte-Array ? on Wed, 20 Apr 2005 21:31:22 GMT]]></title><description><![CDATA[<p>wohl die beste seite um file formate zu parsen<br />
<a href="http://www.wotsit.org/" rel="nofollow">http://www.wotsit.org/</a></p>
<p>Manfred Schmidtke schrieb:</p>
<blockquote>
<p>Eine PNG-Datei ist keine BMP-Datei. Letztere hat eine eindeutige Dateistruktur und man kann jedes Pixel direkt über ein BYTE-Array ansprechen.</p>
</blockquote>
<p>ich denke schon das man png in ein byte array laden kann bzw. bin mir sogar ziemlich sicher, denn in der spieleprogrammierung erstellt man texturen meistens<br />
nur aus rohen pixeldaten unterschiedlicher formate und png ist eins davon.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/771709</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771709</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Wed, 20 Apr 2005 21:31:22 GMT</pubDate></item><item><title><![CDATA[Reply to PNG Bild in Byte-Array ? on Wed, 20 Apr 2005 21:55:52 GMT]]></title><description><![CDATA[<p>Schon klar, jedes Bildformat kann man in ein byte-array packen. Nur das mit Bitmaps dazu nicht erst noch umwandeln muss (sofern nicht RLE komprimiert...)</p>
<p>Als GDI+ Fan schlage ich vor, die png-Datei über GDI+ zu laden <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";D"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/771733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/771733</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Wed, 20 Apr 2005 21:55:52 GMT</pubDate></item></channel></rss>