C#-string生成图片
public static Bitmap GetLink(string Wordstr)
{
#region older
//arial
//StrForImg sf = new StrForImg();
//sf.Adaptable = false;
//sf.BackgroundImage = "";
//sf.BgColor = Color.White;
//sf.FontFamily = "arial";
//sf.FontSize = 10;
//sf.FontStyle = FontStyle.Regular;
//sf.Height = 15;
//sf.Text = Wordstr;
//sf.Width = Wordstr.Length * 10;
//sf.ResultImage = "c:\\a.bmp";
//sf.Top = 0;
//sf.Left = 0;
//Color bl = Color.Green;
//sf.Alpha = bl.A;
//sf.Red = bl.R;
//sf.Green = bl.G;
//sf.Blue = bl.B;
//try
//{
// return sf.Create();
//}
//catch { return null; }
#endregion
try
{
Size TextSize = TextRenderer.MeasureText(Wordstr, new Font(new FontFamily("Arial"), 10, FontStyle.Regular));
Bitmap b = StrForImg_New.DrawTextBmp(Wordstr, new Font(new FontFamily("Arial"), 10, FontStyle.Regular), Color.FromArgb(0,128,0), TextSize, 0, 0, 0, 0);
b = StrForImg_New.ClearWhite(b);
return b;
}
catch { return null; }
}
public static Bitmap DrawTextBmp(string ch, Font font, Color color, Size TextSize, int x, int y, int w, int h)
{
//创建此大小的图片
Bitmap bmp = new Bitmap(TextSize.Width - x, TextSize.Height - y);
//使用GDI+绘制
Graphics g = Graphics.FromImage(bmp);
bmp = new Bitmap(TextSize.Width - x, TextSize.Height - y, PixelFormat.Format64bppArgb);
g = Graphics.FromImage(bmp);
g.Clear(Color.White);
g.DrawString(ch, font, new SolidBrush(color), new PointF(w, h));
g.Save();
g.Dispose();
//返回图像
return bmp;
}
//去白边
public static Bitmap ClearWhite(Bitmap bm)
{
int y_l = 0;//左边
int y_r = 0;//右边
int i_h = 0;//上边
int i_d = 0;//下边
#region 计算----
for (int i = 0; i < bm.Width; i++)
{
for(int y=0;y<bm.Height;y++)
{
if (bm.GetPixel(i, y).R != 255 || bm.GetPixel(i, y).B != 255 || bm.GetPixel(i, y).G != 255)
{
y_l = i;
goto yl;
}
}
}
yl:
for (int i = 0; i < bm.Width; i++)
{
for (int y = 0; y < bm.Height; y++)
{
if (bm.GetPixel(bm.Width - i - 1, y).R != 255 || bm.GetPixel(bm.Width - i - 1, y).B != 255 || bm.GetPixel(bm.Width - i - 1, y).G != 255)
{
y_r = i;
goto yr;
}
}
}
yr:
for (int i = 0; i < bm.Height; i++)
{
for (int y = 0; y < bm.Width; y++)
{
if (bm.GetPixel(y, i).R != 255 || bm.GetPixel(y, i).B != 255 || bm.GetPixel(y, i).G != 255)
{
i_h = i;
goto ih;
}
}
}
ih:
for (int i = 0; i < bm.Height; i++)
{
for (int y = 0; y < bm.Width; y++)
{
if (bm.GetPixel(y, bm.Height - i - 1).R != 255 || bm.GetPixel(y, bm.Height - i - 1).B != 255 || bm.GetPixel(y, bm.Height - i - 1).G != 255)
{
i_d = i;
goto id;
}
}
}
id:
#endregion
//创建此大小的图片
Bitmap bmp = new Bitmap(bm.Width - y_l - y_r, bm.Height - i_h - i_d);
Graphics g = Graphics.FromImage(bmp);
//(new Point(y_l, i_h), new Point(0, 0), new Size(bm.Width - y_l - y_r, bm.Height - i_h - i_d));
Rectangle sourceRectangle = new Rectangle(y_l, i_h, bm.Width - y_l - y_r, bm.Height - i_h - i_d);
Rectangle resultRectangle = new Rectangle(0, 0, bm.Width - y_l - y_r, bm.Height - i_h - i_d);
g.DrawImage(bm, resultRectangle, sourceRectangle, GraphicsUnit.Pixel);
return bmp;
}
C#-string生成图片的更多相关文章
- java使用代理 html2canvas 截屏 将页面内容生成图片
1.html2canvas 生成图片简单又好用,但涉及到跨域就会出现问题,官方给出的解决办法是设置代理.基本原理就是在后端将图片的数据生成base64再返回给前端使用.使canvas画布分析元素的时候 ...
- MVC 生成图片,下载文件(图片不存在本地,在网上下载)
/// <summary> /// 生成图片 /// </summary> /// <param name="collection"></ ...
- MVC 生成图片,下载文件
/// <summary> /// 生成图片 /// </summary> /// <param name="collection"></ ...
- JAVA生成图片缩略图、JAVA截取图片局部内容
package com.ares.image.test; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; ...
- echart 图表 在.net中生成图片的方法
经过中午近两个小时的努力,终于可以实现了:echart 图表 在.net中生成图片 以下源代码: 前台页面: <!DOCTYPE html><html><head> ...
- 用html5的canvas生成图片并保存到本地
原文:http://www.2cto.com/kf/201209/156169.html 前端的代码: [javascript] function drawArrow(angle) { ...
- Winform将网页生成图片
今天无意见看到浏览器有将网页生成图片的功能,顿时赶脚很好奇,于是就找了找资料自己做了一个类似的功能. 工具截图:生成后的图片 手动填写网站地址,可选择图片类型和保持图片地址,来生成页面的图片,当图片路 ...
- highcharts 结合phantomjs纯后台生成图片
highcharts 结合phantomjs纯后台生成图片 highcharts 这个图表展示插件我想大家应该都知道,纯javascript编写,相比那些flash图表插件有很大的优势,至少浏览器不用 ...
- 基于新浪sae使用php生成图片发布图文微博
1.生成图片的代码: <?php header ("Content-type: image/png"); mb_internal_encoding("UTF-8&q ...
随机推荐
- Elasticsearch 模块 - Shard Allocation 机制
原文 1. 背景 shard allocation 意思是分片分配, 是一个将分片分配到节点的过程; 可能发生该操作的过程包括: 初始恢复(initial recovery) 副本分配(replica ...
- C# 应用 - 封装类访问 Postgresql 数据库
引入库类 连接数据库 访问数据库 1)增删改数据库 2)查数据库 数据转换 事务 1. 引入库类 引入 Npgsql.dll using Npgsql; using NpgsqlTypes; 2. 连 ...
- EmEditor, 在正则使用()匹配后 使用$1 $2进行对括号内的值进行引用
$1表示第一个括号,$2表示第二个括号,以此类推
- MD摘要算法
import static org.junit.Assert.*; import java.security.MessageDigest; //消息摘要 public class MDCoder { ...
- 2019HDU多校第七场 HDU6651 Final Exam
一.题目 Final Exam 二.分析 题目说的比较绕,总之一定要记住,$n$个题目都可以做,至少作对$k$到,但是做题目的人不知道每道题对应的分数. 作为出题人,如果他是田忌,肯定不会去在做题目的 ...
- 文本相似性计算--MinHash和LSH算法
给定N个集合,从中找到相似的集合对,如何实现呢?直观的方法是比较任意两个集合.那么可以十分精确的找到每一对相似的集合,但是时间复杂度是O(n2).此外,假如,N个集合中只有少数几对集合相似,绝大多数集 ...
- SpringBoot学习笔记(四)
本文主要介绍:SpringBoot开发中如何自定义starter 1.什么是starter Starter可以理解为一个可拔插式的插件,提供一系列便利的依赖描述符,您可以获得所需的所有Spring和相 ...
- 推荐一款全能测试开发神器:Mockoon!1分钟快速上手!
1. 说一下背景 在日常开发或者测试工作中,经常会因为下游服务不可用或者不稳定时,通过工具或者技术手段去模拟一个HTTP Server,或者模拟所需要的接口数据. 这个时候,很多人脑海里,都会想到可以 ...
- DBeaver、Navicat、MySQL高频报错及解决方法,此文持续更新
目录 第一坑,没有用管理员身份 第二坑,MySQL 服务无法启动 第三坑,报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost ...
- [Fundamental of Power Electronics]-PART I-2.稳态变换器原理分析-2.4 Cuk变换器实例
2.4 Cuk 变换器 作为第二个示例,考虑图2.20(a)的变换器.该变换器执行类似于降压-升压变换器的直流转换功能:它可以增加或减小直流电压的幅值,并且可以反转极性.使用晶体管和二极管的实际实现如 ...