<?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[Hex zu JPEG. Wie?]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>wie schon oben gennant, möchte ich gerne aus Hex ein Bild machen.<br />
Also ich habe mit meinem Pogramm/Code:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;

using namespace std;

int main()
{
   ifstream In;
   ofstream Out;
   char ch;

   In.open( &quot;bild.jpg&quot;, ios::binary );
   Out.open( &quot;Output.txt&quot;, ios::app );

  while( In.get(ch) )
    Out &lt;&lt; hex &lt;&lt; (((int)ch) &amp; 0xFF);	
}
</code></pre>
<p>Eine Output.txt Datei erstellt. In dieser sind Hex Zahlen bzw. Buchstaben drin.<br />
Jetzt möchte ich aus der Datei Output.txt wieder ein bild.jpg bekommen.</p>
<p>Wie mache ich das???</p>
<p>In Wikipedia habe ich mir schon den Bericht über Jpeg auf Deutsch und Englisch angeguckt. Verstanden habe ich schon was da drin steht. Aber wirklich anfangen kann ich damit nix. In dem Artikel stand irgendwas zum Dekodieren indem man<br />
0x00 verwendet statt 0xFF. Dann stehen aber in der Jpeg Datei nur Nullen.</p>
<p>Hat irgendjemand eine Idee?</p>
<p>////// Ich benutzte Dev-Cpp hierfür, habe aber auch Visual Cpp</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/252285/hex-zu-jpeg-wie</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 14:32:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/252285.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 17 Oct 2009 13:58:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sat, 17 Oct 2009 13:58:11 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>wie schon oben gennant, möchte ich gerne aus Hex ein Bild machen.<br />
Also ich habe mit meinem Pogramm/Code:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;

using namespace std;

int main()
{
   ifstream In;
   ofstream Out;
   char ch;

   In.open( &quot;bild.jpg&quot;, ios::binary );
   Out.open( &quot;Output.txt&quot;, ios::app );

  while( In.get(ch) )
    Out &lt;&lt; hex &lt;&lt; (((int)ch) &amp; 0xFF);	
}
</code></pre>
<p>Eine Output.txt Datei erstellt. In dieser sind Hex Zahlen bzw. Buchstaben drin.<br />
Jetzt möchte ich aus der Datei Output.txt wieder ein bild.jpg bekommen.</p>
<p>Wie mache ich das???</p>
<p>In Wikipedia habe ich mir schon den Bericht über Jpeg auf Deutsch und Englisch angeguckt. Verstanden habe ich schon was da drin steht. Aber wirklich anfangen kann ich damit nix. In dem Artikel stand irgendwas zum Dekodieren indem man<br />
0x00 verwendet statt 0xFF. Dann stehen aber in der Jpeg Datei nur Nullen.</p>
<p>Hat irgendjemand eine Idee?</p>
<p>////// Ich benutzte Dev-Cpp hierfür, habe aber auch Visual Cpp</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793840</guid><dc:creator><![CDATA[Gothen111]]></dc:creator><pubDate>Sat, 17 Oct 2009 13:58:11 GMT</pubDate></item><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sat, 17 Oct 2009 17:29:36 GMT]]></title><description><![CDATA[<p>Was willst du machen?</p>
<p>Was für hex zeichen sind in dieser Datei drin?</p>
<p>Willst du etwas wie folgendes machen?</p>
<p>1. bild1.jpg auslesen und in text.txt speichern<br />
2. text.txt auslesen und in bild2 speichern.</p>
<p>allgemein empfehle ich dev-cpp in den mülleimer zu schmeißen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793914</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793914</guid><dc:creator><![CDATA[Fencer]]></dc:creator><pubDate>Sat, 17 Oct 2009 17:29:36 GMT</pubDate></item><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sat, 17 Oct 2009 18:33:06 GMT]]></title><description><![CDATA[<p>Wenn du es so machst, werden Bytes mit Werten &lt;16 nur &quot;einstellig&quot; in die Datei geschrieben, was das Rekonstruieren nachher unmöglich macht.<br />
Mit Streammanipulatoren kannst du das trotzdem hinbiegen:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
#include &lt;iomanip&gt;
using namespace std;

int main()
{  
  ifstream in;
  ofstream out;

  in.open(&quot;bild.jpg&quot;,ios::binary);
  out.open(&quot;output.txt&quot;,ios::trunc);

  out &lt;&lt; hex &lt;&lt; setfill('0');
  while (in.good())out &lt;&lt; setw(2) &lt;&lt; in.get();
}
</code></pre>
<p>Umgekehrt z.B. so:</p>
<pre><code class="language-cpp">#include &lt;fstream&gt;
using namespace std;

static inline int hexCharToInt(char ch)
{
  if (ch&gt;='0' &amp;&amp; ch&lt;='9')return ch-'0';
  if (ch&gt;='a' &amp;&amp; ch&lt;='f')return ch-'a'+10;
  if (ch&gt;='A' &amp;&amp; ch&lt;='F')return ch-'A'+10;
  return 0;
}

static inline unsigned char hexPairToByte(char hi,char lo)
{
  return (hexCharToInt(hi)&lt;&lt;4)|hexCharToInt(lo);
}

int main()
{
  ifstream in;
  ofstream out;

  in.open(&quot;output.txt&quot;,ios::binary);
  out.open(&quot;bild2.jpg&quot;,ios::binary | ios::trunc);

  char ch,ch2;
  while(!in.eof() &amp;&amp; in.get(ch) &amp;&amp; in.get(ch2))out &lt;&lt; hexPairToByte(ch,ch2);  
}
</code></pre>
<p>Edit: Ach ja, und Dev-C++ solltest du umgehend durch <a href="http://forums.codeblocks.org/index.php/topic,11311.0.html" rel="nofollow">Code::Blocks</a> ersetzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793935</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793935</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Sat, 17 Oct 2009 18:33:06 GMT</pubDate></item><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sat, 17 Oct 2009 19:11:18 GMT]]></title><description><![CDATA[<p>Cool, vielen Dank und auch für die schnellen Antworten.<br />
Funktioniert alles.</p>
<p>Jetzt habe ich nocheinmal eine frage zu z.B.:</p>
<pre><code class="language-cpp">static inline int hexCharToInt(char ch)
</code></pre>
<p>Warum macht man nicht normal:</p>
<pre><code class="language-cpp">int hexCharToInt(char ch)
</code></pre>
<p>Wofür ist das &quot;static inline&quot; gut?</p>
<p>Und wofür steht das:</p>
<pre><code class="language-cpp">setw(2)
</code></pre>
<p>Beim ersten Output?</p>
<p>Vielen Dank nochmal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793955</guid><dc:creator><![CDATA[Gothen111]]></dc:creator><pubDate>Sat, 17 Oct 2009 19:11:18 GMT</pubDate></item><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sat, 17 Oct 2009 19:19:56 GMT]]></title><description><![CDATA[<p>static inline kannst du auch weglassen.<br />
inline weist den Compiler an, den Code der Funktion möglichst direkt an die Stelle des Funktionsaufruf einzufügen, so dass der eigentliche Aufruf komplett entfallen kann. Moderne Compiler ignorieren inline aber meist sowieso, da sie selbst (besser) entscheiden können, ob es Sinn macht, die Funktion zu inlinen oder nicht.</p>
<p>static weist die Funktion als lokal aus (d.h. wenn du eine weitere Funktion namens hexCharToInt in einer anderen Übersetzungseinheit hast, wird sich der Linker nicht beschweren).</p>
<p>setw(2) setzt durch, dass die nächste Streamausgabe zwei Zeichen breit ist, der Rest wird mit Nullen aufgefüllt (dafür das setfill('0') zuvor).<br />
Das kannst du aber auch hier nachlesen (und alle anderen Fragen zur Standardbibliothek beantwortet dir die Seite auch):<br />
<a href="http://www.cplusplus.com/reference/iostream/manipulators/setw/" rel="nofollow">http://www.cplusplus.com/reference/iostream/manipulators/setw/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793956</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793956</guid><dc:creator><![CDATA[Nanyuki]]></dc:creator><pubDate>Sat, 17 Oct 2009 19:19:56 GMT</pubDate></item><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sat, 17 Oct 2009 20:50:42 GMT]]></title><description><![CDATA[<p>Okay danke nochmal.<br />
Hab nun alles verstanden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1793998</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1793998</guid><dc:creator><![CDATA[Gothen111]]></dc:creator><pubDate>Sat, 17 Oct 2009 20:50:42 GMT</pubDate></item><item><title><![CDATA[Reply to Hex zu JPEG. Wie? on Sun, 18 Oct 2009 11:35:25 GMT]]></title><description><![CDATA[<p>Offiziell sollte man statt &quot;static&quot; bei Funktionen besser anonyme Namensbereiche verwenden (aber ich benutze sie auch nicht immer -):</p>
<pre><code class="language-cpp">namespace
{

inline int hexCharToInt(char ch)
{
  ...
}

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1794163</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1794163</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 18 Oct 2009 11:35:25 GMT</pubDate></item></channel></rss>