c# – WindowsForm上的图像!= TextRenderer.DrawText()图像
当我发布
here,我能够在我的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:myFoldertest.bmp",System.Drawing.Imaging.ImageFormat.Bmp); Bit.Dispose(); (Code 128是一个特殊的字体,如果你真的想知道更多关于它,只是在下面的链接klick了解更多信息) 所以这是工作,我得到我的形象,很好.现在我在与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; } 当我们看到相同的字体,使用相同的字符串.我没有得到它 解决方法
你发布了错误的代码,它是关闭的位图版本.看起来像UEST给我一个显眼的一个一个的错误.
这不是唯一的问题,即使你修复它仍然不是一个有效的Code128条形码.您还需要开始,检查和停止字符,如本Wikipedia article所述.您可能接近不可避免的“购买,不建立”结论.找到生成条形码的控件并不困难或昂贵. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |