我正在开发一个用于Led显示器的Winforms应用程序。 LED显示屏尺寸为64x32。我创建了一个64x16的测试bitmap image with 4 cells,所以我可以将它输出到LED显示屏。
当用户在输入表单中输入4个数字时,这些字符串将转换为位图图像并放置在单元格内。我以某种方式使用这种方法;它编辑相同的位图图像,插入数字,并将其保存到新的bmp(或者我错了吗?)。
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System
Public Class abc
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub OnPropertyChanged(ByVal info As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
End Sub
Protected Sub OnNotifyPropertyChanged(propertyName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
Private Property _Msg As String
Private Property _Color As String
Public Property Msg As String
Get
Return _Msg
End Get
Set(value As String)
_Msg = value
OnPropertyChanged("Msg")
OnNotifyPropertyChanged("Msg")
End Set
End Property
Public Property Color As String
Get
Return _Color
End Get
Set(value As String)
_Color = value
OnPropertyChanged("Color")
OnNotifyPropertyChanged("Color")
End Set
End Property
Public Sub New()
For i = 10 To 0 Step -1
System.Threading.Thread.Sleep(500)
Select Case i
Case 11, 10, 9, 8
Msg = "Wait" + i.ToString
Color = "Green"
Case 7, 6, 5, 4
Msg = "Start" + i.ToString
Color = "Yellow"
Case Is < 3
Msg = "End" + i.ToString
Color = "Red"
End Select
Next
End Sub
End Class
PictureBox中的输出为This
现在我已经在对齐方面创造了多个问题,因为我只是粘贴了#b; bmp数字&#34;直接进入&#34; bmp单元格&#34; ...是否有&#34;映射&#34;单元格内的数字是否正确,取决于它是一位数还是两位数?
我非常肯定有一种更简单的方法来完成所有这些,可能使用DataGridView?我只是开始使用C#,任何帮助都将不胜感激。
图像&#34; cells.bmp&#34;我只是在Paint(xd)中创建的测试图像,而不是那个,我试图编写一个通过代码创建Bitmap单元格的函数
public static Bitmap Convert_Text_to_Image(string txt, string fontname, int fontsize)
{
//creating bitmap image
Bitmap bmp = new Bitmap("cells.bmp");
//FromImage method creates a new Graphics from the specified Image.
Graphics graphics = Graphics.FromImage(bmp);
// Create the Font object for the image text drawing.
Font font = new Font(fontname, fontsize);
// Instantiating object of Bitmap image again with the correct size for the text and font.
SizeF stringSize = graphics.MeasureString(txt, font);
bmp = new Bitmap(bmp, (int)stringSize.Width, (int)stringSize.Height);
graphics = Graphics.FromImage(bmp);
//Draw Specified text with specified format
graphics.DrawString(txt, font, Brushes.Red, 0, 0);
font.Dispose();
graphics.Flush();
graphics.Dispose();
bmp.Save("cells2.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
return bmp; //return Bitmap Image
}