- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
正如我发布的 here ,我能够在我的 WindowsForm 上显示一些特殊字体但是我无法将这种字体保存为图片。问题是 Graphic.DrawString()
无法显示所有或特殊字体。 WindowsForm 使用 TextRenderer
及其更新版本(随 2.0 添加),这就是 WindowsForm 能够显示这些字体的原因。
很好。现在我坐在这里并尝试用 TextRenderer.DrawText()
做同样的事情 - 我不得不说我的输出图像现在好多了但仍然不一样在窗体上。让我们看看我的代码:
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是一种特殊的字体,如果你真的想了解更多信息,请点击下面的链接了解更多信息)
所以这是有效的,我得到了我的形象,很好。现在,我在同一个 VS 项目中添加具有相同字体的相同字符串作为我的 WindowsForm 上的标签。并且有一些区别。不同之处在于,使用 TextRenderer
创建的图像在第一个位置总是有一个不同的字符。其他一切都很好!我不明白。让我们看看 WinForm VS 图像:
正如我们所看到的,第一个“字符”(如果我们可以在这个例子中说“字符”)在某种程度上是不一样的。现在让我将 TextRenderer Image 函数中的字符串更改为“TTEST”。将 WinForm 上的“TEST”与 TextRenderer Image 上的“TTEST”进行比较:
看起来很有趣吧?所以,TextRenderer.DrawText()
+ special font = first char 很奇怪。但为什么?以及如何解决这个问题?有什么建议么?谢谢!
编辑:如果有帮助,我可以发布 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 条形码。您还需要 Start、Check 和 Stop 字符,如本 Wikipedia article 中所述.您可能接近不可避免的“购买,不构建”结论。寻找生成条形码的控件并不困难也不昂贵。
关于c# - Windows 窗体上的图像 != TextRenderer.DrawText() 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11868465/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!