<?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[Text in Bitmap (anhand Textlänge)]]></title><description><![CDATA[<p>Ich habe folgendes Problem:</p>
<p>Ich habe einen CString, den ich in ein CBitmap packe. Der Text wird mittels Edit-Feld im Dialog eingegebne und soll dann in das Bitmap &quot;reingemalt&quot; werden. Klappt auch soweit ganz gut. Nur habe ich das Problem, dass ich bis jetzt eine Feste Breite angebe um das Bitmap zu zeichnen. Ich würde aber gerne haben, dass das Bitmap die Breite bekommt, die der Text hat. Habe es mit .GetLength versucht, aber leider entsprechen die Zeichen ja nicht den Pixeln für die einzelnen Zeichen. Gibt es eine Funktion, die das umrechnet oder muss ich mit einem Pauschalwert von Bsp. 5 Pixel pro Zeichen rechnen.</p>
<p>Hier meine Zeichenfunktion:</p>
<pre><code class="language-cpp">void Cproj_1Dlg::TextToBitmap(CString value, int pos_x, int pos_y)
{
    CBitmap cBitmap;
    CDC cDC;
    CDC* pDC = this-&gt;GetDC();
    int loop = 0;
    int wBit = 0;

//TextCount = value.GetLength();

    //Create a bitmap and set the options
    cDC.CreateCompatibleDC(pDC);
    cDC.SetBkColor(RGB(0,0,0));
    cDC.SetTextColor(RGB(255,255,255));
    cBitmap.CreateCompatibleBitmap(pDC, 64, 8); //&lt;- Erstellen des Bitmaps mit breite 64pixel und Höhe 8pixel 

    //Select the bitmap and write into it
    cDC.SelectObject(&amp;cBitmap);
    cDC.SelectObject(&amp;cFont);
    cDC.TextOutW(pos_x, pos_y, value, TextCount); 

    pDC-&gt;StretchBlt(20, 20, 128, 32,&amp; cDC, 0, 0, 32, 8, SRCCOPY);

    cDC.DeleteDC(); 
    cBitmap.DeleteObject();
}
</code></pre>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/202157/text-in-bitmap-anhand-textlänge</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 11:39:51 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/202157.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 08 Jan 2008 10:13:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Text in Bitmap (anhand Textlänge) on Tue, 08 Jan 2008 10:13:45 GMT]]></title><description><![CDATA[<p>Ich habe folgendes Problem:</p>
<p>Ich habe einen CString, den ich in ein CBitmap packe. Der Text wird mittels Edit-Feld im Dialog eingegebne und soll dann in das Bitmap &quot;reingemalt&quot; werden. Klappt auch soweit ganz gut. Nur habe ich das Problem, dass ich bis jetzt eine Feste Breite angebe um das Bitmap zu zeichnen. Ich würde aber gerne haben, dass das Bitmap die Breite bekommt, die der Text hat. Habe es mit .GetLength versucht, aber leider entsprechen die Zeichen ja nicht den Pixeln für die einzelnen Zeichen. Gibt es eine Funktion, die das umrechnet oder muss ich mit einem Pauschalwert von Bsp. 5 Pixel pro Zeichen rechnen.</p>
<p>Hier meine Zeichenfunktion:</p>
<pre><code class="language-cpp">void Cproj_1Dlg::TextToBitmap(CString value, int pos_x, int pos_y)
{
    CBitmap cBitmap;
    CDC cDC;
    CDC* pDC = this-&gt;GetDC();
    int loop = 0;
    int wBit = 0;

//TextCount = value.GetLength();

    //Create a bitmap and set the options
    cDC.CreateCompatibleDC(pDC);
    cDC.SetBkColor(RGB(0,0,0));
    cDC.SetTextColor(RGB(255,255,255));
    cBitmap.CreateCompatibleBitmap(pDC, 64, 8); //&lt;- Erstellen des Bitmaps mit breite 64pixel und Höhe 8pixel 

    //Select the bitmap and write into it
    cDC.SelectObject(&amp;cBitmap);
    cDC.SelectObject(&amp;cFont);
    cDC.TextOutW(pos_x, pos_y, value, TextCount); 

    pDC-&gt;StretchBlt(20, 20, 128, 32,&amp; cDC, 0, 0, 32, 8, SRCCOPY);

    cDC.DeleteDC(); 
    cBitmap.DeleteObject();
}
</code></pre>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1432897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432897</guid><dc:creator><![CDATA[Uruk-h4j]]></dc:creator><pubDate>Tue, 08 Jan 2008 10:13:45 GMT</pubDate></item><item><title><![CDATA[Reply to Text in Bitmap (anhand Textlänge) on Tue, 08 Jan 2008 12:34:39 GMT]]></title><description><![CDATA[<p>-&gt; <strong>GetDeviceCaps</strong> wäre einen Blick wert <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>grüssle <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1432972</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1432972</guid><dc:creator><![CDATA[Smitty]]></dc:creator><pubDate>Tue, 08 Jan 2008 12:34:39 GMT</pubDate></item><item><title><![CDATA[Reply to Text in Bitmap (anhand Textlänge) on Tue, 08 Jan 2008 13:15:48 GMT]]></title><description><![CDATA[<p>Bringt mich nicht wirklich weiter... In welchem Zusammenhag soll ich das bitte nutzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1433002</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433002</guid><dc:creator><![CDATA[Uruk-h4j]]></dc:creator><pubDate>Tue, 08 Jan 2008 13:15:48 GMT</pubDate></item><item><title><![CDATA[Reply to Text in Bitmap (anhand Textlänge) on Tue, 08 Jan 2008 13:31:35 GMT]]></title><description><![CDATA[<p>war wohl etwas schreibfaul <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>GetDeviceCaps -&gt; LOGPIXELSX</p>
<p>Bei LOGFONT( MSDN ) nachschauen, ist ein Beispiel zur Umrechnung für die Höhe. Auf die Breite übertragen und du hast die Breite deines Bitmaps in Points. Dann in Pixel, ist halt ne ewige rechnerei.<br />
also: Stringlänge x Länge( einzelnes Zeichen );</p>
<p>Aber vllt gehts auch schneller / einfacher.</p>
<p>grüssle <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1433015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433015</guid><dc:creator><![CDATA[Smitty]]></dc:creator><pubDate>Tue, 08 Jan 2008 13:31:35 GMT</pubDate></item><item><title><![CDATA[Reply to Text in Bitmap (anhand Textlänge) on Tue, 08 Jan 2008 14:17:02 GMT]]></title><description><![CDATA[<p>Leider ist das nicht das richtige.</p>
<pre><code class="language-cpp">cFont.CreateFontW(10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T(&quot;Small Fonts&quot;));

LOGFONT font;
cFont.GetLogFont(&amp;font);
PixelFont = font.lfWidth;
</code></pre>
<p>Wenn ich das so mache, dann habe ich eine lfWidth von 0. Wenn ich in CreateFont() die Breite der Schrift auf z.B.4 stelle, dann ist lfWidth auch 4, aber das entspricht nicht der wirklichen Breite des Zeichens ('A' z.B. hat in der Schriftart &quot;SmallFonts&quot; eine Breite von 5 Pixeln, 'F' nur 4). Und er passt die Zeichen auch nicht dementsprechend an. Das bringt mich also nicht wirklich weiter.</p>
<p>EDIT:<br />
HAb gerade herrausgefunden, dass 5 die kleinste Zeichenbreite ist <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1433047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1433047</guid><dc:creator><![CDATA[Uruk-h4j]]></dc:creator><pubDate>Tue, 08 Jan 2008 14:17:02 GMT</pubDate></item></channel></rss>