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 面向对象 04

    面向对象·四级 多态的概述及其代码实现 * A:多态(polymorphic)概述 * 事物存在的多种形态 * B:多态前提 * a:要有继承关系 * b:要有方法重写 * c: 要有父类引用指向子类 ...

  2. 话说CAS

    一.前言 cas 一般认为是compare and swap 也可以认为是compare and set cas涉及三个值 1)P 变量内存地址 2)E 期望值 ,CPU做计算之前拿出来的旧值 3) ...

  3. 安卓Media相关类测试demo

    最近在研究安卓系统给app开发者提供的标准Media相关的工具类,本人做了一些demo来测试这些工具的使用方法. 本demo包含若干apk源码,需要说明以下几点: 1. 构建方式 Makefile使用 ...

  4. [源码分析] 消息队列 Kombu 之 Hub

    [源码分析] 消息队列 Kombu 之 Hub 0x00 摘要 本系列我们介绍消息队列 Kombu.Kombu 的定位是一个兼容 AMQP 协议的消息队列抽象.通过本文,大家可以了解 Kombu 中的 ...

  5. Java8 Stream 中 List 转 Map 问题总结

    在使用 Java 的新特性 Collectors.toMap() 将 List 转换为 Map 时存在一些不容易发现的问题,这里总结一下备查. 空指针风险 java.lang.NullPointerE ...

  6. Bonuses on a Line Gym - 102569B

    题目链接:https://vjudge.net/problem/Gym-102569B 题意:数轴上有N个点,从0出发最多走t步问最多经过几个点. 思路:分开存负数点和整数点,然后枚举每个端点,某个点 ...

  7. POj1860(floyd+正权回路)

    题目传送门 题意:有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0.39,那么你可以得到(100 - 0.39) * 29.75 = 296 ...

  8. python3表格数据处理

    技术背景 数据处理是一个当下非常热门的研究方向,通过对于大型实际场景中的数据进行建模,可以用于预测下一阶段可能出现的情况.比如我们有过去的2002年-2018年的黄金价格的数据: 该数据来源于Gite ...

  9. 文字变图片——GitHub 热点速览 v.21.14

    作者:HelloGitHub-小鱼干 程序的力量,在 deep-daze 体现得淋漓尽致,你用一句话描述下你的图片需求,它就能帮你生成对应图片.同样的,appsmith 的力量在于你只要拖拽即可得到一 ...

  10. 【Flutter 3-5】Flutter进阶教程——在Flutter中使用Lottie动画

    作者 | 弗拉德 来源 | 弗拉德(公众号:fulade_me) Lottie动画 在移动开发中总是需要展示一些动画特效,作为程序员的我们并不是很擅长用代码做动画,即便是有些动画可以实现,在跨平台的过 ...