简体   繁体   English

显示图像上的数据库值

[英]Display Database value on an Image

I would like to know if there's a way to display database value on an image, like I have a image template of a certificate and i would like to display name from the database, cause I have like 1000 names and there Image have to be made, is it possible from me to make ac# app for that. 我想知道是否有办法在图像上显示数据库值,就像我有一个证书的图像模板,我想显示数据库中的名称,因为我有1000个名字,那里必须有图像,我可以为此制作ac#app。 Im sorry new to this I did searches but i can't find anything. 我很抱歉,我做了搜索,但我找不到任何东西。

Thanks 谢谢

You can do it by the GDI+ drawing in .NET. 你可以通过.NET中的GDI +绘图来实现。 first, load your template image, then draw a string to it, then save it as a new image. 首先,加载模板图像,然后为其绘制一个字符串,然后将其另存为新图像。 load all the names from database and process them in a loop, that will be ok. 从数据库加载所有名称并在循环中处理它们,这样就可以了。 what you must focus on is to find the proper drawing position and beautify the font, my sample is below: 你必须关注的是找到合适的绘图位置并美化字体,我的样本如下:

private void btnDrawImage_Click(object sender, EventArgs e)
    {
        string templateFile = Application.StartupPath + Path.DirectorySeparatorChar + "template_picture.jpg";
        //customerize your dispaly string style
        Font ft = new System.Drawing.Font("SimSun", 24);
        Brush brush = Brushes.Red;
        //start position(x,y)
        Point startPt = new Point(100, 100);
        //names from database
        var nameList = new List<string>(){
            "scott yang",
            "Vivi",
            "maxleaf",
            "lenka"};
        //process image on every name
        foreach (string name in nameList)
        {
            string msg = "Welcome " + name;
            Image templateImage = Image.FromFile(templateFile);
            Graphics g = Graphics.FromImage(templateImage);
            g.DrawString(msg, ft, brush, startPt.X, startPt.Y);
            g.Dispose();
            string savePath = "c:\\" + name + ".jpg";
            templateImage.Save(savePath);
        }
    }

here is my result, I hope it is helpful to you. 这是我的结果,我希望它对你有所帮助。 我的测试结果我的测试结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM