该功能配合卡片彩色打印机和RFID卡制作人员信息卡片,主要用于人员身份信息的核实。

引用 system.drawing

g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; //去掉字体黑边

效果图和源代码如下:

using System;
using System.Drawing;namespace TestImage
{class Program{static void Main(string[] args){Image image = Image.FromFile(@"C:\Users\MelanceXin\source\repos\TestImage\TestImage\bin\Debug\image.png");Image codeImage = Image.FromFile(@"C:\Users\MelanceXin\source\repos\TestImage\TestImage\bin\Debug\code.jpg");Person person = new Person{name = "曾振帅",org_name = "天津某某某某有限公司",personal_type_name = "现场负责人",work_type_name = "高压安装修造作业"};//保存制好之后的图片的完整路径string empcard_path = @"C:\Users\MelanceXin\source\repos\TestImage\TestImage\bin\Debug\pic\empcard.jpg";bool b = CreateImageModel(person, image, codeImage, empcard_path);image.Dispose();codeImage.Dispose();string result = b ? "制卡成功!!!!!" : "制卡失败!!";Console.WriteLine(result);Console.ReadKey();}/// <summary>/// 绘制卡片/// </summary>/// <param name="picimage"></param>/// <param name="codeimage"></param>/// <param name="empcard_path"></param>/// <returns></returns>public static bool CreateImageModel(Person person, Image picimage, Image codeimage, string empcard_path){Image image = Image.FromFile(@"C: \Users\MelanceXin\source\repos\TestImage\TestImage\bin\Debug\0.png");Bitmap bitmap = new Bitmap(image);Graphics g = Graphics.FromImage(image);try{bitmap = new Bitmap(image, new Size(1024, 638));bitmap.SetResolution(300, 300);g = Graphics.FromImage(bitmap);//标题StringFormat format = new StringFormat();format.LineAlignment = StringAlignment.Center;  // 更正: 垂直居中format.Alignment = StringAlignment.Center;      // 水平居中StringFormat format1 = new StringFormat();format1.LineAlignment = StringAlignment.Center;  // 更正: 垂直居中format1.Alignment = StringAlignment.Near;      // 水平居左StringFormat format2 = new StringFormat();format2.LineAlignment = StringAlignment.Center;  // 更正: 垂直居中format2.Alignment = StringAlignment.Far;      // 水平居右//证件照Image id_image = picimage;RectangleF id_rec = new Rectangle(new Point(130, 140), new Size(250, 320));g.DrawImage(id_image, id_rec);//二维码Image qrcode_image = codeimage;//Image qrcode_image = Image.FromFile(@_empinfo.Qrcode_path);RectangleF qrcode_rec = new Rectangle(new Point(630, 240), new Size(320, 320));g.DrawImage(qrcode_image, qrcode_rec);g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;   //去掉字体黑边//文字信息//人员姓名RectangleF nameval_rec = new Rectangle(new Point(20, 470), new Size(480, 60));g.DrawString(person.name, new Font("黑体", 12f, (FontStyle.Bold)), new SolidBrush(Color.FromArgb(95, 95, 95)), nameval_rec, format);//公司名称RectangleF coval_rec = new Rectangle(new Point(20, 510), new Size(480, 100));//g.DrawString(person_.org_name, new Font("黑体", 7f), Brushes.LightGray, coval_rec, format);g.DrawString(person.org_name, new Font("宋体", 7f), new SolidBrush(Color.FromArgb(95, 95, 95)), coval_rec, format);//人员类别RectangleF type_rec = new Rectangle(new Point(600, 50), new Size(340, 60));g.DrawString(person.personal_type_name, new Font("微软雅黑", 10f), Brushes.White, type_rec, format2);工种RectangleF worktype_rec = new Rectangle(new Point(600, 110), new Size(340, 50));g.DrawString(person.work_type_name, new Font("微软雅黑", 7f), Brushes.White, worktype_rec, format2);bitmap.Save(empcard_path);}finally{image.Dispose();bitmap.Dispose();g.Dispose();}return true;}}public class Person{public string name;public string org_name;public string personal_type_name;public string work_type_name;}
}

C# 运用 System.Drawing 绘制卡片 (解决:去掉DrawString写出的字体黑边)相关推荐

  1. System.Drawing.Common workaround in .NET6

    System.Drawing.Common workaround in .NET6 Intro 最近有不少小伙伴在升级 .NET 6 时遇到了 System.Drawing.Common 的问题,同时 ...

  2. 调用C# System.Drawing 画图

    最近公司有个需求,根据处方数据画一张处方图片,方便给用户展示及下载打印. 废话不多说,直接上代码. 第一步:模拟一个get请求: public string Get(int id){var hostU ...

  3. C# Pen绘制虚线(System.Drawing.Pen与System.Windows.Media.Pen)

    一.绘制虚线的方法 GDI绘制,使用的是System.Drawing.Pen Pen pen = new Pen(Color.Red, 1); pen.DashStyle = System.Drawi ...

  4. .Net Core 之 图形验证码 本文介绍.Net Core下用第三方ZKWeb.System.Drawing实现验证码功能。...

    本文介绍.Net Core下用第三方ZKWeb.System.Drawing实现验证码功能. 通过测试的系统: Windows 8.1 64bit Ubuntu Server 16.04 LTS 64 ...

  5. System.Drawing.Printing.InvalidPrinterException: 未安装打印机。

    未安装打印机. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.Drawing.Prin ...

  6. 未能加载文件或程序集 System Drawing Version 4 0 0 0 Culture neutral

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 完整错误 ...

  7. 关于UNITY中System.Drawing引用失败的处理方法

    关于UNITY中System.Drawing引用失败的处理方法 今天在使用EPPlus中,遇到一个处于This type has been forwarded to assembly 'System. ...

  8. unity 引用using System.Drawing.Printing

    .NET类库System.Drawing提供了一系列的图形函数,但由于其使用的是GDI接口,与DirectX和OpenGL之间不兼容,在Unity中默认是不被支持的. 但有时候,我们想在Unity中使 ...

  9. C#遇到System.Drawing.Bitmap有问题

    C#处理bitmap数据时,遇到 error CS0246: 未能找到类型或命名空间名"Bitmap"(是否缺少 using 指令或程序集引用?) 貌似是因为缺少 System.D ...

最新文章

  1. 基于Hash的消息认证码HMAC简介及在OpenSSL中使用举例
  2. 打造专属BGM,​Python 深度学习教你
  3. VUE的本地应用-V- on
  4. unix环境高级编程 pdf_UNIX系统编程宝典,每一本都值得程序员珍藏
  5. Unity3d--跨平台(一)
  6. python3 读取写入excel操作-win32com
  7. GPS围栏两个多边形相交问题的奇葩解法
  8. Java中常见定时任务的实现方式
  9. mysql笛卡尔积效率_SQL优化 MySQL版 -分析explain SQL执行计划与笛卡尔积
  10. java jhat_java自带命令行工具jmap、jhat与jinfo的使用实例代码详解
  11. 前端bugger 后端debug 介绍系统内部逻辑 压测新增订单接口 tps上不去 ,oom ,常见性能问题 ,性能分析思路
  12. 哈德森喜迎万分夜 CBA“第一外援”就此易主?
  13. 苹果6标准模式和放大模式具体有什么差别?
  14. dwf怎么合成一个_图纸集批量发布单页dwf的方法——院办质量小组
  15. 数据库-订单信息表(单表)_思路清晰_设计简洁
  16. 用ArcGIS Server服务Print打印高清大图的关键参数
  17. spark steaming的性能问题
  18. 乐视笔试算法题美团算法笔试题
  19. 利用PDF编辑软件给PDF添加页码的操作全过程
  20. K8S初识!!kubeadm快速部署

热门文章

  1. PHP几种常用的魔术方法
  2. 2021年危险化学品经营单位安全管理人员考试题库及危险化学品经营单位安全管理人员理论考试
  3. pdmreader支持读取xml格式的pdm文件,无法读取二进制格式的pdm文件。
  4. 在x86_64平台搭建飞腾ARM交叉编译环境
  5. windows镜像网站 含win10日文
  6. Go语言Append函数的使用
  7. java读取1g超大图片_java读取大文件1G+ | 学步园
  8. ARM学习笔记 计算机结构 总线 南北桥
  9. U盘安装windows10时显示 windows无法安装到这个磁盘
  10. 饥荒单机,强大的斧子