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中枚举Enum详解

    1.关键字:enum.枚举可以定义成单独的文件,也可以定义在其他类内部. 枚举在类内部的示例: public class EnumInner { public static void main(Str ...

  2. SpringMVC-03 RestFul和控制器

    SpringMVC-03 RestFul和控制器 控制器Controller 控制器复杂提供访问应用程序的行为,通常通过接口定义或注解定义两种方法实现. 控制器负责解析用户的请求并将其转换为一个模型. ...

  3. WPF 基础 - 绘画 1) 线段、矩形、圆弧及填充色

    1. 绘画 1.1 图形类型 Line X1.Y1.X2.Y2,Stroke,StrokeThickness Rectangle 矩形 Ellipse 椭圆 Polygon 多边形(自动闭合) Pol ...

  4. Java方法:练习,控制台简易计算器

    可以更改计算个数的简易计算器 package com.zdz.method; import java.util.Scanner; public class Operator { public stat ...

  5. 题解 CF746D 【Green and Black Tea】

    # 题目分析这道题表面上看上去挺简单,其实仔细研究一下还是值得钻研的.我本人做这道题使用的任然是$ DFS01 $背包.不过呢,与往常背包不同的是,这次递归中需要加许多参数.就数据强度来看,栈问题不大 ...

  6. P1618 三连击(升级版)(JAVA语言)

    题目描述 将1,2,-,9共9个数分成三组,分别组成三个三位数,且使这三个三位数的比例是A:B:C,试求出所有满足条件的三个三位数,若无解,输出"No!!!". //感谢黄小U饮品 ...

  7. 图解 | 原来这就是 class

    我是一个 .java 文件,名叫 FlashObject.java,叫我小渣就行. public class FlashObject {    private String name;    priv ...

  8. Android Studio 之 BaseAdapter 学习笔记

    •前行必备--ListView的显示与缓存机制 我们知道 ListView.GridView 等控件可以展示大量的数据信息. 假如下图中的 ListView 可以展示 100 条信息,但是屏幕的尺寸是 ...

  9. Python代码简化

    让代码更Pythonic 当然不要过分追求简洁,不然阅读的人就遭殃了, 部分逻辑复杂的情况还应按照清晰的逻辑脉络去写方便阅读, 毕竟我们是用代码实现功能然后维护,而不是单单的炫技. ######### ...

  10. 第22 章 : 有状态应用编排 StatefulSet

    有状态应用编排 StatefulSet 本文将主要分享以下四方面的内容: "有状态"需求 用例解读 操作演示 架构设计 "有状态"需求 课程回顾 我们之前讲到过 ...