<?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[Bild kopieren in GDI+]]></title><description><![CDATA[<p>Hallo, <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=";)"
      alt="😉"
    /></p>
<p>ich habe folgendes Beispiel fast 1:1 aus der MSDN kopiert:</p>
<pre><code>INT main()
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;
    // Initialize GDI+.
    GdiplusStartup(&amp;gdiplusToken, &amp;gdiplusStartupInput, NULL);
    std::cout &lt;&lt; &quot;Starte GDI+&quot; &lt;&lt; std::endl;

    CLSID   encoderClsid;
    Status  stat;
    Image*   image = new Image(L&quot;C:\\Quelle.bmp&quot;);

    // Get the CLSID of the PNG encoder.
    if(GetEncoderClsid(L&quot;image/png&quot;, &amp;encoderClsid))
        printf(&quot;Codec image/png gefunden\n&quot;);
    else
        printf(&quot;Codec image/png nicht gefunden\n&quot;);

    stat = image-&gt;Save(L&quot;C:\\Ziel.png&quot;, &amp;encoderClsid, NULL);

    if(stat == 0)
        printf(&quot;Ziel.png gespeichert\n&quot;);
    else
        printf(&quot;Fehler: %d\n&quot;, stat);

    delete image;
    GdiplusShutdown(gdiplusToken);
    return 0;
}
</code></pre>
<p>Selbst bei diesem simplen Programm erhalte ich jedoch einen Fehler:</p>
<pre><code>Starte GDI+
Codec image/png gefunden
Fehler: 10
</code></pre>
<p>Die Ziel.png wird zwar angelegt, ist aber 0 Bytes groß.<br />
Die Quelle.bmp ist in jedem Fall am angegebenen Pfad vorhanden, lässt sich per MSPaint anzeigen und wird zur Laufzeit auch nicht von anderen Programmen verwendet. Versuche, die Datei zu verschieben und den Pfad entsprechend anzupassen, scheiterten, der Fehler blieb.</p>
<p>MSDN sagt:</p>
<pre><code>Status 10 - FileNotFound

    Indicates that the specified image file or metafile cannot be found.
</code></pre>
<p>Ich weiß nicht mehr weiter und Google schweigt zu dem Thema. Gibt es vielleicht jemanden, der in derselben Situation steckte?</p>
<p>Ich verwende MinGW/GCC als Compiler und Windows XP SP2 als OS.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/217005/bild-kopieren-in-gdi</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 13:10:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/217005.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Jul 2008 21:28:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Tue, 01 Jul 2008 21:28:11 GMT]]></title><description><![CDATA[<p>Hallo, <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=";)"
      alt="😉"
    /></p>
<p>ich habe folgendes Beispiel fast 1:1 aus der MSDN kopiert:</p>
<pre><code>INT main()
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;
    // Initialize GDI+.
    GdiplusStartup(&amp;gdiplusToken, &amp;gdiplusStartupInput, NULL);
    std::cout &lt;&lt; &quot;Starte GDI+&quot; &lt;&lt; std::endl;

    CLSID   encoderClsid;
    Status  stat;
    Image*   image = new Image(L&quot;C:\\Quelle.bmp&quot;);

    // Get the CLSID of the PNG encoder.
    if(GetEncoderClsid(L&quot;image/png&quot;, &amp;encoderClsid))
        printf(&quot;Codec image/png gefunden\n&quot;);
    else
        printf(&quot;Codec image/png nicht gefunden\n&quot;);

    stat = image-&gt;Save(L&quot;C:\\Ziel.png&quot;, &amp;encoderClsid, NULL);

    if(stat == 0)
        printf(&quot;Ziel.png gespeichert\n&quot;);
    else
        printf(&quot;Fehler: %d\n&quot;, stat);

    delete image;
    GdiplusShutdown(gdiplusToken);
    return 0;
}
</code></pre>
<p>Selbst bei diesem simplen Programm erhalte ich jedoch einen Fehler:</p>
<pre><code>Starte GDI+
Codec image/png gefunden
Fehler: 10
</code></pre>
<p>Die Ziel.png wird zwar angelegt, ist aber 0 Bytes groß.<br />
Die Quelle.bmp ist in jedem Fall am angegebenen Pfad vorhanden, lässt sich per MSPaint anzeigen und wird zur Laufzeit auch nicht von anderen Programmen verwendet. Versuche, die Datei zu verschieben und den Pfad entsprechend anzupassen, scheiterten, der Fehler blieb.</p>
<p>MSDN sagt:</p>
<pre><code>Status 10 - FileNotFound

    Indicates that the specified image file or metafile cannot be found.
</code></pre>
<p>Ich weiß nicht mehr weiter und Google schweigt zu dem Thema. Gibt es vielleicht jemanden, der in derselben Situation steckte?</p>
<p>Ich verwende MinGW/GCC als Compiler und Windows XP SP2 als OS.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539352</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Tue, 01 Jul 2008 21:28:11 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 10:11:42 GMT]]></title><description><![CDATA[<p>Verstehe auch nicht, dass der Fehler beim Aufruf von ::Save passiert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539556</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Wed, 02 Jul 2008 10:11:42 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 10:51:11 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ändere diesen Teil:</p>
<pre><code class="language-cpp">// Get the CLSID of the PNG encoder. 
    if(GetEncoderClsid(L&quot;image/png&quot;, &amp;encoderClsid)) 
        printf(&quot;Codec image/png gefunden\n&quot;); 
    else 
        printf(&quot;Codec image/png nicht gefunden\n&quot;);
</code></pre>
<p>in:</p>
<pre><code class="language-cpp">if(GetEncoderClsid(L&quot;image/png&quot;, &amp;encoderClsid) &gt;= 0) 
        printf(&quot;Codec image/png gefunden\n&quot;); 
    else 
        printf(&quot;Codec image/png nicht gefunden\n&quot;);
</code></pre>
<p>um zu sehen, ob der Encoder wirklich vorhanden ist.</p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539585</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539585</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Wed, 02 Jul 2008 10:51:11 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 11:31:23 GMT]]></title><description><![CDATA[<p>Ich mach das ähnlich, aber mit Bitmap anstelle Image, so klappt das.</p>
<p>Gruss Frank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539621</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539621</guid><dc:creator><![CDATA[DerAltenburger]]></dc:creator><pubDate>Wed, 02 Jul 2008 11:31:23 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 11:44:17 GMT]]></title><description><![CDATA[<p>Wird nichts ändern, da die Funktion BOOL zurückgibt:</p>
<pre><code>BOOL GetEncoderClsid(wchar_t* wchMimeType, CLSID* clsidEncoder)
{
    UINT uiNum   = 0;
    UINT uiSize  = 0;
    BOOL bOk     = FALSE;

    ImageCodecInfo* pImageCodecInfo = NULL;

    GetImageEncodersSize(&amp;uiNum, &amp;uiSize);

    if( uiSize &gt; 0 )
    {
        pImageCodecInfo = (Gdiplus::ImageCodecInfo *)new char[uiSize];

        if( pImageCodecInfo )
        {
            Gdiplus::GetImageEncoders(uiNum, uiSize, pImageCodecInfo);

            for( UINT i = 0; i &lt; uiNum; i++ )
            {
                if( wcscmp(pImageCodecInfo[i].MimeType, wchMimeType) == 0 )
                {
                    clsidEncoder = &amp;pImageCodecInfo[i].Clsid;
                    bOk = TRUE;
                    break;
                }
            }
        }

        delete pImageCodecInfo;
    }

   return bOk;
}
</code></pre>
<p>Ein paar Testläufe mit teilweise erfundenen Werten:</p>
<pre><code>Codec image/bmp gefunden

Codec image/asdf nicht gefunden

Codec image/png gefunden

Codec image/test nicht gefunden

Codec image/jpeg gefunden
</code></pre>
<p>Der Teil scheint also zu funktionieren?</p>
<p>Unabhängig davon, ob der Codec vorhanden ist, erhalte ich den Fehler 10.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/2128">@DerAltenburger</a>: Danke, werde ich mal ausprobieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539634</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539634</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Wed, 02 Jul 2008 11:44:17 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 12:01:01 GMT]]></title><description><![CDATA[<p>Habe über Google gefunden, dass man Unicode-Pfaden ein \?\ voranstellen muss/kann.</p>
<pre><code>Bitmap* image = Bitmap::FromFile(L&quot;\\\\?\\Quelle.bmp&quot;);
...
stat = image-&gt;Save(L&quot;\\\\?\\Ziel.png&quot;, &amp;encoderClsid, NULL);
</code></pre>
<p>So erhalte ich einen Fehler 2:</p>
<blockquote>
<p>InvalidParameter</p>
<p>Indicates that one of the arguments passed to the method was not valid.</p>
</blockquote>
<p>Etwas weiter gelesen:</p>
<blockquote>
<p>Also, you cannot use the &quot;\?\&quot; prefix with a relative path.</p>
</blockquote>
<p>Also statische Pfade getestet:</p>
<pre><code>Bitmap* image = Bitmap::FromFile(L&quot;\\\\?\\C:\\Quelle.bmp&quot;);
...
stat = image-&gt;Save(L&quot;\\\\?\\C:\\Ziel.png&quot;, &amp;encoderClsid, NULL);
</code></pre>
<p>Dann erhalte ich wieder Fehler 10, File not found.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539647</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Wed, 02 Jul 2008 12:01:01 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 12:09:32 GMT]]></title><description><![CDATA[<p>@Altenburger: Ersetzen von Image durch Bitmap ändert leider nichts.</p>
<p>Folgendes hinzugefügt:</p>
<pre><code>FILE *datei;
    datei= fopen(&quot;Quelle.bmp&quot;,&quot;r&quot;);
    if (datei == NULL)
        std::cout &lt;&lt; &quot;Quelle.bmp existiert nicht&quot; &lt;&lt; std::endl;
    else
        std::cout &lt;&lt; &quot;Quelle.bmp existiert!&quot; &lt;&lt; std::endl;
</code></pre>
<p>ergibt:</p>
<blockquote>
<p>Quelle.bmp existiert!</p>
</blockquote>
<p>Der Bitmap::Save-Fehler 10 bleibt jedoch, langsam gehen mir die Ideen aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539650</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Wed, 02 Jul 2008 12:09:32 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 12:33:36 GMT]]></title><description><![CDATA[<p>Sorry für das Multiposting, aber mir fehlen die Rechte zum Beiträge bearbeiten.</p>
<pre><code>UINT height = image-&gt;GetHeight();
    UINT width = image-&gt;GetWidth();

    std::cout &lt;&lt; &quot;Hoehe: &quot; &lt;&lt; height &lt;&lt; &quot;, Breite: &quot; &lt;&lt; width &lt;&lt; std::endl;
</code></pre>
<p>Dieser Code gibt die korrekten Bildmaße wieder, das Bild wurde also geöffnet. Nur der Save-Aufruf schlägt fehl mit &quot;File not found&quot; (Logik?), selbst wenn &quot;image/bmp&quot; als Encoder verwendet wird.</p>
<blockquote>
<p>FileNotFound</p>
<p>Indicates that the specified image file or metafile cannot be found.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1539670</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539670</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Wed, 02 Jul 2008 12:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 12:39:49 GMT]]></title><description><![CDATA[<p>GdiGast schrieb:</p>
<blockquote>
<p>Habe über Google gefunden, dass man Unicode-Pfaden ein \?\ voranstellen muss/kann.</p>
<pre><code>Bitmap* image = Bitmap::FromFile(L&quot;\\\\?\\Quelle.bmp&quot;);
...
stat = image-&gt;Save(L&quot;\\\\?\\Ziel.png&quot;, &amp;encoderClsid, NULL);
</code></pre>
<p>So erhalte ich einen Fehler 2:</p>
<blockquote>
<p>InvalidParameter</p>
<p>Indicates that one of the arguments passed to the method was not valid.</p>
</blockquote>
<p>Etwas weiter gelesen:</p>
<blockquote>
<p>Also, you cannot use the &quot;\?\&quot; prefix with a relative path.</p>
</blockquote>
<p>Also statische Pfade getestet:</p>
<pre><code>Bitmap* image = Bitmap::FromFile(L&quot;\\\\?\\C:\\Quelle.bmp&quot;);
...
stat = image-&gt;Save(L&quot;\\\\?\\C:\\Ziel.png&quot;, &amp;encoderClsid, NULL);
</code></pre>
<p>Dann erhalte ich wieder Fehler 10, File not found.</p>
</blockquote>
<p>Nein, völlig auf der falschen Spur (du hast doch geschrieben, die Datei wurde angelegt, der Pfad kann nicht das Problem sein), würde ich sagen...zum Thema:</p>
<pre><code class="language-cpp">Wird nichts ändern, da die Funktion BOOL zurückgibt:
</code></pre>
<p>Stimmt, jetzt da man auch sieht, wie die in der MSDN-Doku angegebene Funktion geändert wurde (ich bin von der anderen Funktion ausgegangen, dann muss man ändern) <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=";)"
      alt="😉"
    /></p>
<p>und damit kommen wir zum &quot;fast 1:1 -Kopieren&quot;:</p>
<p>Die Funktion wurde so geändert, dass sie nicht mehr zuverlässig funktionieren kann:</p>
<p>hier:</p>
<pre><code class="language-cpp">delete pImageCodecInfo;
</code></pre>
<p>wird das pImageCodecInfo-Objekt abgeräumt, und es verweist noch ein Zeiger (clsidEncoder) darauf, der dann auch noch weiter verwendet werden soll.</p>
<p>Aber entscheidender ist, dass in der Funktion GetEncoderClsid zwar mit dem Wert von &amp;encoderClsid gearbeitet wird, jedoch bringt die Zuweisung:</p>
<p>clsidEncoder = &amp;pImageCodecInfo[i].Clsid;</p>
<p>überhaupt nichts, da einem lokalen Zeiger mit dem Namen clsidEncoder zwar ein neuer Wert zugewiesen wird (der übergebene Wert &amp;encoderClsid wird überschrieben), aber der übergebene Zeiger &amp;encoderClsid behält (natürlich) seinen Wert, so dass das encoderClsid-Objekt nicht verändert wird (und damit wird dort nie ein gültiger Encoder vorhanden sein).</p>
<p>Die in der MSDN-Doku vorgestellte Funktion hat dieses Problem nicht, da mit der Zuweisung:</p>
<pre><code class="language-cpp">*pClsid = pImageCodecInfo[j].Clsid;
</code></pre>
<p>der Wert, auf den der Zeiger verweist, geändert wird, und das ist ok. Vielleicht weisst du jetzt, was du ändern musst, wenn du unbedingt mit der geänderten Funktion weiter arbeiten willst...</p>
<p>MfG,</p>
<p>Probe-Nutzer</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539673</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539673</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Wed, 02 Jul 2008 12:39:49 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 12:53:27 GMT]]></title><description><![CDATA[<p>Vielleicht fehlen dir einfach nur die Rechte eine datei in C:\ zu erstellen?<br />
Mach das doch mal auf dem desktop.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539688</guid><dc:creator><![CDATA[fewwfefwe]]></dc:creator><pubDate>Wed, 02 Jul 2008 12:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to Bild kopieren in GDI+ on Wed, 02 Jul 2008 13:28:06 GMT]]></title><description><![CDATA[<p>@Probe-Nutzer: Bist mein Held des Tages. Riesen-Dank.</p>
<p>Kann geschlossen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1539725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1539725</guid><dc:creator><![CDATA[GdiGast]]></dc:creator><pubDate>Wed, 02 Jul 2008 13:28:06 GMT</pubDate></item></channel></rss>