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;
}

最新文章

  1. 【swift】BlockOperation和GCD实用代码块
  2. CSS 居中方法集锦
  3. tnsnames.ora 监听配置文件详解
  4. TRF7960天线参数试验
  5. 安全通信 QSslSocket
  6. WebService CXF调试常见报错及解决方案
  7. virtualBox文件共享
  8. LDAP研究
  9. apk反汇编之smali语法
  10. 页面json 格式化+颜色高亮
  11. ngRx 官方示例分析 - 1. 介绍
  12. Java读取证书
  13. Flutter工程无法找到Android真机或Android模拟器
  14. conda添加多个版本的python
  15. CentOS 7下安装Python3.6
  16. Action&lt;T&gt; Delegate
  17. Vue源码之 virtual-dom 实现简析
  18. 【总结】redis和memcached的区别
  19. 多个jsp页面共享Java bean
  20. C++中的乱七八糟问题

热门文章

  1. Spring笔记(10) - 日志体系
  2. golang——win10环境protobuf的使用
  3. FreeBSD 如何让csh像zsh那样具有命令错误修正呢
  4. C# 通过ServiceStack 操作Redis——String类型的使用及示例
  5. 记一次scrapy-redis爬取小说网的分布式搭建过程
  6. 制作API离线chm帮助文件教程
  7. Hznu_0j 1533 计算球体积(水)
  8. 使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换
  9. 在ASP.NET Core中用HttpClient(六)——ASP.NET Core中使用HttpClientFactory
  10. python多版本与虚拟环境