ここに投稿したように、WindowsForm にいくつかの特殊なフォントを表示できましたが、このフォントを画像として保存できませんでした。問題は、Graphic.DrawString()
すべてまたは特殊なフォントを表示できないことでした。WindowsForm が使用してTextRenderer
おり、その新しい (2.0 で追加された) ため、WindowsForm はこれらのフォントを表示できました。
罰金。今、私はここに座って同じことをしようとしていますTextRenderer.DrawText()
- 私の出力画像は今でははるかに良くなっていると言わざるを得ませんが、それでも WindowsForm と同じではありません。私のコードを見てみましょう:
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 128 は特別なフォントです。詳しく知りたい場合は、以下のリンクをクリックして詳細を確認してください)
だからこれはうまくいっている、私は自分のイメージを得る。今、私は WindowsForm の Label と同じ VS Project に同じフォントで同じ文字列を追加しています。そして、いくつかの違いがあります。違いは、 で作成されたイメージTextRenderer
は最初の位置で常に異なる文字を取得することです。他のすべては大丈夫です!理解できません。WinForm VS Image を見てみましょう:
ご覧のとおり、最初の「文字」(この例で「文字」と言える場合) は、どういうわけか同じではありません。ここで、TextRenderer Image 関数の文字列を "TTEST" に変更します。WinForm の "TEST" と TextRenderer イメージの "TTEST" を比較します。
面白そうですよね?だから、TextRenderer.DrawText()
+特殊フォント=最初の文字は変です。しかし、なぜ?そして、これを修正する方法は?助言がありますか?ありがとうございました!
編集:それが役立つ場合は、WindowsFormのコードを投稿できます
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
ご覧のとおり、同じ文字列を持つ同じフォントです。理解できません...