C#图像处理(3):在图像上加条形码
引入Aspose.BarCode用来生成条形码,方法如下:
/// <summary>
/// 生成条码
/// </summary>
/// <param name="CodeString">生成条码的字符串</param>
/// <param name="Path">条码保存的路径</param>
/// <returns>条码保存的路径</returns>
public bool CreateBarCode(string CodeString, string Path)
{
try
{
Aspose.BarCode.BarCodeBuilder builder = new Aspose.BarCode.BarCodeBuilder(CodeString, Symbology.GS1Code128);
//string filenameurl = Application.StartupPath + @"\xxx.gif";
builder.BorderVisible = false;
builder.BarHeight = 10f;
builder.BorderWidth = 30f;
builder.BorderDashStyle = Aspose.BarCode.BorderDashStyle.Solid;
builder.CodeLocation = CodeLocation.Below;
MarginsF Margin = new MarginsF(, , , );
builder.Margins = Margin;
if (!System.IO.File.Exists(Path))
{
builder.Save(Path);
}
else
{
System.IO.File.Delete(Path);
builder.Save(Path);
}
builder.Dispose();
}
catch (Exception ex)
{
return false;
}
return true; ;
}
将条形码加入到图片的指定位置:
/// <summary>
/// 图片上方加条码,条码将会被180度反转
/// </summary>
/// <param name="Img">待处理图片</param>
/// <param name="ImgBarCode">写入的条码</param>
/// <param name="UpMargin">180度反转后条码顶部距离上边缘距离</param>
/// <param name="RightMargin">条码最左边距离右边缘距离</param>
/// <returns></returns>
public Bitmap BarCodeUp(Image Img, Image ImgBarCode, int UpMargin, int RightMargin)
{
//获取图片宽高
int Width = Img.Width;
int Height = Img.Height;
//获取图片水平和垂直的分辨率
float dpiX = Img.HorizontalResolution;
float dpiY = Img.VerticalResolution;
//创建一个位图文件
Bitmap BitmapResult = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
//设置位图文件的水平和垂直分辨率 与Img一致
BitmapResult.SetResolution(dpiX, dpiY);
//在位图文件上填充一个矩形框
Graphics Grp = Graphics.FromImage(BitmapResult);
System.Drawing.Rectangle Rec = new System.Drawing.Rectangle(, , Width, Height);
//向矩形框内填充Img
Grp.DrawImage(Img, , , Rec, GraphicsUnit.Pixel); //平移Graphics对象
Grp.TranslateTransform(Width - RightMargin, UpMargin);
//设置Graphics对象的输出角度
Grp.RotateTransform();
//设置条码填充颜色
//Brush brush = Brushes.Black;
//旋转显示条码
//Grp.DrawString(WriteString, new Font(FontType, FontSize), brush, 0, 0);
Grp.DrawImage(ImgBarCode, , );
//恢复全局变换矩阵
Grp.ResetTransform();
Grp.Dispose();
GC.Collect();
return BitmapResult;
}
C#图像处理(3):在图像上加条形码的更多相关文章
- C#图像处理(1):在图片上加文字和改变文字的方向
C#在图片上加文字,代码如下: /// <summary> /// 图片上方加文字,文字将会被180度反转 /// </summary> /// <param name= ...
- 用 Python 和 OpenCV 检测图片上的条形码
用 Python 和 OpenCV 检测图片上的的条形码 这篇博文的目的是应用计算机视觉和图像处理技术,展示一个条形码检测的基本实现.我所实现的算法本质上基于StackOverflow 上的这个问 ...
- 用 Python 和 OpenCV 检测图片上的条形码(转载)
原文地址:http://python.jobbole.com/80448/ 假设我们要检测下图中的条形码: # load the image and convert it to grayscale 1 ...
- [图像]用Matlab在图像上画矩形框
原创文章,欢迎转载.转载请注明:转载自 祥的博客 原文链接:http://blog.csdn.net/humanking7/article/details/46819527 在毕业设计的时候写论文画图 ...
- 数学之路-python计算实战(7)-机器视觉-图像产生加性零均值高斯噪声
图像产生加性零均值高斯噪声.在灰度图上加上噪声,加上噪声的方式是每一个点的灰度值加上一个噪声值.噪声值的产生方式为Box-Muller算法生成高斯噪声. 在计算机模拟中,常常须要生成正态分布的数值.最 ...
- Win8 Metro(C#)数字图像处理--2.50图像运动模糊
原文:Win8 Metro(C#)数字图像处理--2.50图像运动模糊 [函数名称] 图像运动模糊算法 MotionblurProcess(WriteableBitmap src,int ...
- 图像处理---《在图片上打印文字 windows+GDI+TrueType字体》
图像处理---<在图片上打印文字 windows+GDI+TrueType字体> 刚开始使用的是putText()函数做,缺陷是只能显示非中文: 接着,看大多数推荐Freetype库来做 ...
- 图像处理---《在图片上打印文字 FreeType库》
图像处理---<在图片上打印文字 FreeType库> 目的:想在处理之后的图像上打印输出结果.方法: (1)只在图像上打印 数字.字母的话: 1.Mat格式 ...
- 图像处理---《在图片上打印文字 putText()》
图像处理---<在图片上打印文字 putText()> 目的:想在处理之后的图像上打印输出结果. 方法: (1)只在图像上打印 数字.字母的话: 1.Mat ...
随机推荐
- js带箭头左右翻动控制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java学习笔记(3):java的工作原理及相关基础
一.运行机制 如上图所示,图中内容即为Java的运行机制: 1.我们一开始所编写的代码文件存储格式为(如text.java)文件,这就是源程序文件 2.在Java编辑器的作用下,也就是就行了编译,形成 ...
- Linux下添加磁盘创建lvm分区
shell> fdisk /dev/xvdb #### 选择磁盘 Command (m for help): m #### 帮助 Command action a toggle a bootab ...
- document 写法
# UfsProgressBar ## Component InfoA progress bar component of specified progress. ## Usage```<ufs ...
- php 获取网站根目录的写法
路径方式,代码如下: define('BASE_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/"); ...
- jquery正则表达式显示文本框输入范围 只能输入数字、小数、汉字、英文字母的方法
正则表达式限制文本框只能输入数字 许多时候我们在制作表单时需要限制文本框输入内容的类型,下面我们用正则表达式限制文本框只能输入数字.小数点.英文字母.汉字等各类代码.1.文本框只能输入数字代码(小数点 ...
- MySQL flush tables with read lock
mysql> flush tables with read lock; flush tables with read lock 会去关闭已经打开的所有文件,它要做这个操作就先要拿到锁:当发起这个 ...
- 关于offsetWidth innerWidth的使用
最近因为有使用到offsetWidth 和innerWidth,刚开始以为这两个属性在jq何js之中是可以通用的,谁知道在js中使用innerWidth时,发现如果对页面元素使用它时,发现出来的是un ...
- UI控件自定义tableView的分割线的样式
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFi ...
- data语意学
引例: class X{}; class Y:public virtual X{}; class Z:public virtual X{}; class A:public Y,public Z{}; ...