C#随机产生图片

mac2024-08-20  64

public string CreateImage(string name)  {//From:www.uzhanbao.com             int initialWidth = 50, initialHeight = 50;             Bitmap theBitmap = new Bitmap(initialWidth, initialHeight);             Graphics theGraphics = Graphics.FromImage(theBitmap);             //呈现质量             theGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;             //背景色             theGraphics.Clear(Color.Transparent);                        Brush b = ColorUtils.GetOneBrush();             theGraphics.FillEllipse(b, new Rectangle(0, 0, 50, 50));               Font font = new Font("宋体", 13, FontStyle.Bold);             SizeF sizeF = theGraphics.MeasureString(name, font);                           theGraphics.DrawString(name + "", font, Brushes.Wheat, (initialWidth - sizeF.Width) / 2, (initialHeight-sizeF.Height)/2);               string path = "Images\\" + DateTime.Now.ToString("yy_MM_dd") + DateTime.Now.ToString("HH_mm_ss_fff") + ".png";             theBitmap.Save(path);                          return ImageUtils.ImageFileToBase64String(path); ;   } ?

最新回复(0)