Note that there are some explanatory texts on larger screens.

plurals
  1. POImage on WindowsForm != TextRenderer.DrawText() image
    primarykey
    data
    text
    <p>As I posted <a href="https://stackoverflow.com/questions/11557513/why-is-it-not-possible-to-save-any-font-as-image-but-to-display-it-on-my-windo">here</a>, I was able to display some special fonts on my WindowsForm <strong>but</strong> I was not able to save this font as picture. The problem was that <code>Graphic.DrawString()</code> is not able to display all or special fonts. WindowsForm is using <code>TextRenderer</code> and its newer (added with 2.0) thats why WindowsForm was able to display these fonts.</p> <p>Fine. Now Im sitting here and trying to do the same stuff with <code>TextRenderer.DrawText()</code> - I have to say that my output image is now much better <strong>but</strong> still not the same as on the WindowsForm. Lets look at my code:</p> <pre><code> Bitmap Bit = new Bitmap(500, 200); Graphics g = Graphics.FromImage(Bit); string s = "TEST"; g.Clear(Color.White); TextRenderer.DrawText(g, s, new Font("Code 128", 72), new Point(20, 20), Color.Black, Color.White); Bit.Save(@"C:\myFolder\test.bmp", System.Drawing.Imaging.ImageFormat.Bmp); Bit.Dispose(); </code></pre> <p>(Code 128 is a special font, if you really want to know more about it just klick on the link below for more information)</p> <p>So this is working, I get my image, fine. Now Im adding the same string with the same font on the same VS Project as Label on my WindowsForm. And there is some difference. The difference is that the image created with <code>TextRenderer</code> got always a different character at the first position. Everything else is fine! I dont get it. Lets have a look WinForm VS Image:</p> <p><img src="https://i.stack.imgur.com/FwWnu.jpg" alt="WindowsForm with Label VS TextRenderer Image (same string and the font)"></p> <p>As we can see the first "character" (if we can say 'character' for this example) is somehow not the same. Now let me change my string in my TextRenderer Image function to "TTEST". Compare "TEST" on WinForm with "TTEST" on TextRenderer Image:</p> <p><img src="https://i.stack.imgur.com/Nr9bR.jpg" alt="enter image description here"></p> <p>Looks interesting right? So, <code>TextRenderer.DrawText()</code> + special font = first char is weird. But why? And how to fix this? Any suggestions? Thank you!</p> <p>Edit: If it helps I can post the Code of the WindowsForm</p> <pre><code>partial class Form1 { /// &lt;summary&gt; /// Required designer variable. /// &lt;/summary&gt; private System.ComponentModel.IContainer components = null; /// &lt;summary&gt; /// Clean up any resources being used. /// &lt;/summary&gt; /// &lt;param name="disposing"&gt;true if managed resources should be disposed; otherwise, false.&lt;/param&gt; protected override void Dispose(bool disposing) { if (disposing &amp;&amp; (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Code 128", 72F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(2))); this.label1.Location = new System.Drawing.Point(30, 41); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(144, 94); this.label1.TabIndex = 0; this.label1.Text = "TEST"; this.label1.Click += new System.EventHandler(this.label1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.label1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1; } </code></pre> <p>As we see its the same font, with the same string. I dont get it...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload