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生成图片的更多相关文章

  1. java使用代理 html2canvas 截屏 将页面内容生成图片

    1.html2canvas 生成图片简单又好用,但涉及到跨域就会出现问题,官方给出的解决办法是设置代理.基本原理就是在后端将图片的数据生成base64再返回给前端使用.使canvas画布分析元素的时候 ...

  2. MVC 生成图片,下载文件(图片不存在本地,在网上下载)

    /// <summary> /// 生成图片 /// </summary> /// <param name="collection"></ ...

  3. MVC 生成图片,下载文件

    /// <summary> /// 生成图片 /// </summary> /// <param name="collection"></ ...

  4. JAVA生成图片缩略图、JAVA截取图片局部内容

    package com.ares.image.test; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; ...

  5. echart 图表 在.net中生成图片的方法

    经过中午近两个小时的努力,终于可以实现了:echart 图表 在.net中生成图片 以下源代码: 前台页面: <!DOCTYPE html><html><head> ...

  6. 用html5的canvas生成图片并保存到本地

    原文:http://www.2cto.com/kf/201209/156169.html 前端的代码: [javascript]  function drawArrow(angle)  {      ...

  7. Winform将网页生成图片

    今天无意见看到浏览器有将网页生成图片的功能,顿时赶脚很好奇,于是就找了找资料自己做了一个类似的功能. 工具截图:生成后的图片 手动填写网站地址,可选择图片类型和保持图片地址,来生成页面的图片,当图片路 ...

  8. highcharts 结合phantomjs纯后台生成图片

    highcharts 结合phantomjs纯后台生成图片 highcharts 这个图表展示插件我想大家应该都知道,纯javascript编写,相比那些flash图表插件有很大的优势,至少浏览器不用 ...

  9. 基于新浪sae使用php生成图片发布图文微博

    1.生成图片的代码: <?php header ("Content-type: image/png"); mb_internal_encoding("UTF-8&q ...

随机推荐

  1. Java 基础加强 02

    基础加强·反射 和 枚举 类的加载概述和加载时机 * A:类的加载概述 * 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载.连接.初始化来实现对这个类的初始化 * 加载 * 就是指 ...

  2. ElasticSearch(ES)使用Nested结构存储KV及聚合查询

    自建博客地址:https://www.bytelife.net,欢迎访问! 本文为博客同步发表文章,为了更好的阅读体验,建议您移步至我的博客 本文作者: Jeffrey 本文链接: https://w ...

  3. 漫漫Java路1—基础知识—初涉java

    前言 主学信息安全,在编程的路上还是一个孩子,还在一步一步探索,有些东西可能是站在自己的位置思考的,很可能会出现一些啼笑皆非的错误,如果有误,还希望各位斧正. Java安装 jdk的安装 甲骨文官网选 ...

  4. Centos mini系统下的Hadoop集群搭建

    1.事前了解 1.1 Hadoop 百度百科:https://baike.baidu.com/item/Hadoop/3526507?fr=aladdin Hadoop是一个由Apache基金会所开发 ...

  5. Django之cookie 与session组件

    一.会话跟踪技术 1.1 什么是会话跟踪 我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话,你就是客户端,而 ...

  6. python flake8 代码扫描

    一.介绍 Flake8 是由Python官方发布的一款辅助检测Python代码是否规范的工具,flake8是下面三个工具的封装: PyFlakes Pep8 NedBatchelder's McCab ...

  7. python课程设计--学生管理系统

    系统要求 1.添加学生 2.删除学生 3.修改学生信息 4.查询学生 5.查看所有学生信息 6.学生信息数据的存储与读取 源码:student.py #coding:utf-8 2 #定义学员类 3 ...

  8. Just a Joke HDU - 4969(物理+积分)

    题目链接:https://vjudge.net/problem/HDU-4969#author=0 题意:一个人在圆心以V2速度追赶一个以V1的速度进行圆周运动,问在圆心的人能否在不超过D的距离追上他 ...

  9. PTA 二叉树的三种遍历(先序、中序和后序)

    6-5 二叉树的三种遍历(先序.中序和后序) (6 分)   本题要求实现给定的二叉树的三种遍历. 函数接口定义: void Preorder(BiTree T); void Inorder(BiTr ...

  10. Web 前端 - 浅谈外部手动控制 Promise 状态

    前言 当有多个共享资源.协同操作的时候,往往需要根据动态亦或是复杂的条件以控制和调用程序逻辑. 还是那句话,懂的人自然懂,不懂的人也搜不到这个随笔. 设计 PendingPromise<T> ...