字符转换为位图图像C#

我需要一个字符串数组,例如: a[] = {A,B,C,...,Z}然后从数组中随机选择一个字母并从其上应用windows目录中的字体,然后渲染具有特定宽度和高度的位图图像forms的特定字母(例如,在我的表单中的图像框中将其显示为位图图像)。

嘿,如果我理解你,你需要这样的东西:

 //Create String-Array string[] a = {"A", "B", "C"}; //Create a Image-Object on which we can paint Image bmp = new Bitmap(100, 100); //Create the Graphics-Object to paint on the Bitmap Graphics g = Graphics.FromImage(bmp); //Here we get the random string //Random.Next() gives us the next integer value //Because we dont want to get IndexOutOfBoundException we give the Array length to the Next method //So just the numbers from 0 - Array.Length can be choosen from Next method string randomString = a[new Random().Next(a.Length)]; //Your custom Font (6f = 6px)! Font myFont = new Font("Arial", 6f) //Get the perfect Image-Size so that Image-Size = String-Size SizeF size = g.MeasureString(randomString, myFont); PointF rect = new PointF(size.Width, size.Height); //Use this to become better Text-Quality on Bitmap. g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; //Here we draw the string on the Bitmap g.DrawString(randomString, myFont, new SolidBrush(Color.Black), rect); 

您可以在程序中使用bmp对象。 例如:

 picturebox.Image = bmp; 

我希望你现在能理解它:)如果你有一个问题需要理解Objectdesign,你应该先阅读一本书。 这是免费的;) http://openbook.galileocomputing.de/visual_csharp_2012/

不要犹豫与我联系。 问候