C#实现将Email地址转成图片显示的方法
作者:红薯 时间:2022-09-26 09:35:36
本文实例讲述了C#实现将Email地址转成图片显示的方法。分享给大家供大家参考。具体实现方法如下:
private final static IndexColorModel icm = createIndexColorModel();
/**
* 生成电子邮件图片
* @param email
* @param out
* @throws IOException
*/
public static void MakeEmailImage(String email, OutputStream out) throws IOException {
int height = 22;
BufferedImage bi = new BufferedImage(255,height,BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D)bi.getGraphics();
Font mFont = new Font("Verdana", Font.PLAIN, 14);
g.setFont(mFont);
g.drawString(email, 2, 19);
FontMetrics fm = g.getFontMetrics();
int new_width = fm.charsWidth(email.toCharArray(), 0, email.length()) + 4;
int new_height = fm.getHeight();
BufferedImage nbi = new BufferedImage(new_width, new_height, BufferedImage.TYPE_BYTE_INDEXED, icm);
Graphics2D g2 = (Graphics2D)nbi.getGraphics();
g2.setColor(new Color(0,0,0,0));//透明
g2.fillRect(0,0,new_width,new_height);
g2.setFont(mFont);
g2.setColor(new Color(200,0,0));
g2.drawString(email, 2, new_height-4);
ImageIO.write(nbi, "gif", out);
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mybatis in查询条件过长的解决方案
2022-06-08 12:44:14
![](https://img.aspxhome.com/file/2023/4/70594_0s.png)
Spring Boot项目如何同时支持HTTP和HTTPS协议的实现
2023-11-19 19:57:05
![](https://img.aspxhome.com/file/2023/1/59321_0s.jpg)
解决MyBatis @param注解参数类型错误异常的问题
2023-12-01 06:41:45
解决SpringBoot web项目启动后立即关闭的问题
2023-07-26 02:33:37
![](https://img.aspxhome.com/file/2023/9/64909_0s.png)
spring boot executable jar/war 原理解析
2022-10-13 18:30:09
JetBrains发布java代码质量检测工具Qodana早期预览版
2022-11-22 20:49:57
![](https://img.aspxhome.com/file/2023/7/131837_0s.png)
unity实现摄像头跟随
2021-07-26 12:50:10
Android开发实现图片的上传下载
2022-10-21 03:41:10
![](https://img.aspxhome.com/file/2023/1/97871_0s.jpg)
java Unicode和UTF-8之间转换实例
2023-04-05 01:56:00
![](https://img.aspxhome.com/file/2023/6/70566_0s.jpg)
C#泛型约束的深入理解
2023-02-21 09:32:19
Java实现文本编译器
2022-10-21 18:33:20
![](https://img.aspxhome.com/file/2023/7/77097_0s.jpg)
Spring Boot2中如何优雅地个性化定制Jackson实现示例
2021-09-27 12:21:15
Java基于Socket实现多人聊天室
2022-11-08 14:11:12
C#使用Aspose.Cells创建和读取Excel文件
2022-11-24 17:47:23
![](https://img.aspxhome.com/file/2023/2/75592_0s.jpg)
Flutter持久化存储之数据库存储(sqflite)详解
2022-11-16 04:34:30
C#实现基于IE内核的简单浏览器完整实例
2021-12-04 02:08:02
C#对Word文档的创建、插入表格、设置样式等操作实例
2021-10-24 23:13:46
深入浅析C#泛型类型
2023-01-30 06:45:54
![](https://img.aspxhome.com/file/2023/9/111139_0s.png)
spring aop execution表达式的用法
2023-08-22 05:39:24
![](https://img.aspxhome.com/file/2023/2/88072_0s.png)
Android程序锁的实现以及逻辑
2022-09-29 19:50:57
![](https://img.aspxhome.com/file/2023/4/137234_0s.png)