C# CodeHelper
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BarcodeLib;
using Gma.QrCodeNet.Encoding;
using Gma.QrCodeNet.Encoding.Windows.Render;
using System.Drawing.Imaging;
using System.IO; namespace Utils
{
/// <summary>
/// 条形码/二维码帮助类
/// </summary>
public class CodeHelper
{
/// <summary>
/// 生成条形码
/// </summary>
/// <param name="Code"></param>
public static void CreateBarCode(string Code, string fileName)
{
BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()
{
IncludeLabel = true,
Alignment = AlignmentPositions.CENTER,
Width = ,
Height = ,
RotateFlipType = RotateFlipType.RotateNoneFlipNone,
BackColor = Color.White,
ForeColor = Color.Black,
}; System.Drawing.Image img = barcode.Encode(TYPE.CODE128B, Code);
img.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
//using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
//{
//img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
//HttpContext.Current.Response.ClearContent();
//HttpContext.Current.Response.ContentType = "image/png";
//HttpContext.Current.Response.BinaryWrite(ms.ToArray());
//}
} /// <summary>
/// 生成二维码
/// </summary>
/// <param name="data">二维码内容</param>
/// <param name="filename">生成的图片路径名称(如:D:\123.png)</param>
/// <param name="moduleSize">图片大小</param>
/// <returns></returns>
public static void CreateQRCode(string data, string filename, int moduleSize = )
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
QrCode qrCode = new QrCode();
MemoryStream ms = new MemoryStream();
qrEncoder.TryEncode(data, out qrCode); //GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZoneModules.Two));
//renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms);
//System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
//img.Save(filename, System.Drawing.Imaging.ImageFormat.Png); GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZoneModules.Two), Brushes.Black, Brushes.White);
using (FileStream stream = new FileStream(filename, FileMode.Create))
{
render.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream);
}
} /// <summary>
/// 生成带Logo的二维码
/// </summary>
/// <param name="data"></param>
/// <param name="filename"></param>
/// <param name="logPath"></param>
/// <param name="moduleSize"></param>
public static void CreateQRCodeHasLog(string data, string filename, string logPath, int moduleSize = )
{
QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M);
QrCode qrCode = qrEncoder.Encode(data);
//保存成png文件
GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZoneModules.Two), Brushes.Black, Brushes.White); DrawingSize dSize = render.SizeCalculator.GetSize(qrCode.Matrix.Width);
Bitmap map = new Bitmap(dSize.CodeWidth, dSize.CodeWidth);
Graphics g = Graphics.FromImage(map);
render.Draw(g, qrCode.Matrix);
//追加Logo图片 ,注意控制Logo图片大小和二维码大小的比例
System.Drawing.Image img = System.Drawing.Image.FromFile(logPath);
Point imgPoint = new Point((map.Width - img.Width) / , (map.Height - img.Height) / );
g.DrawImage(img, imgPoint.X, imgPoint.Y, img.Width, img.Height);
map.Save(filename, ImageFormat.Png);
}
}
}
C# CodeHelper的更多相关文章
- iBatis for Net 代码生成器(CodeHelper)附下载地址(已经升级为V 1.1)
CodeHelper是一款可以自己定义模板和生成内容的代码生成器,目前只支持MsSql数据库,这款代码生成器的初衷也只是为了生成MyBatis.net框架的配置文件而写的一个轻量级的代码生成器. Co ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(25)-权限管理系统-系统管理员(附生成器)
系列目录 这一节我们要着手建立系统管理员表,但发布之前,我先发布一个代码生成器给大家先用着. 这个生成器是为这个项目而生的,理论不能用于其他项目,而且写得比较潦草,但能用 下载地址 有兴趣要生成器源码 ...
- 全自动迁移数据库的实现 (Fluent NHibernate, Entity Framework Core)
在开发涉及到数据库的程序时,常会遇到一开始设计的结构不能满足需求需要再添加新字段或新表的情况,这时就需要进行数据库迁移. 实现数据库迁移有很多种办法,从手动管理各个版本的ddl脚本,到实现自己的mig ...
- 分享公司Basecode的用法
主题 公司在basecode的用法上是比较有新意的,所以准备记录分享下公司的用法. 说明 basecode公司的一个主要用途就是用于一些基础的代码表,参数表的前台操作.这些表有很多,用spring d ...
- 使用 Entity Framework Core 时,通过代码自动 Migration
一 介绍 在使用 Entity Framework Core (下面就叫 EF Core 吧)进行开发时,如果模型有变动,我们要在用 EF Core 提供的命令行工具进行手工迁移,然后再运行程序.但是 ...
- 手把手教你用动软.NET代码生成器实例教程
动软实战攻略 手把手教你用动软 文档编号:20110421 版权所有 © 2004-2011 动软 在线帮助:http://help.maticsoft.com 目录 一. 产品介绍 ...
- Orm图解教程
entity framework框架生成摘要文档为空(没有元数据文档可用)的bug解决方案 西安.王磊 2012-10-25 10:47 阅读:1234 评论:2 ORM for Net主流框架汇 ...
- 分享原创可复用且非侵入性代码生成工具(for .net)
入行IT十年了,这是本人第一次网上’献丑‘.迫于工作压力,花了大半年时间写了这个生成器以辅助开发.如有价值请多多给予建议,谢谢 好了,废话少说,开动! QA. 1.为什么要用代码生成器? 当然是为了快 ...
- C# QRCode、DataMatrix和其他条形码的生成和解码软件
今天制造了一个C#的软件,具体是用于生成二维码和条形码的,包括常用的QRCode.DataMatrix.Code128.EAN-8等等. 使用的第三方类库是Zxing.net和DataMatrix.n ...
随机推荐
- des和Rijndael加密
------------IV的作用: 为了保证数据的安全,.NET基类库中提供的私钥算法类使用称作密码块链(CBC,Cipher Block Chaining)的链模式,算法使用一个密钥和一个初始化向 ...
- Oracle琐碎笔记2
备注:以下所有操作均在sqlplus中执行. 开始前输入:spool c:\jiyi.txt;结束后输入:spool off;就会记忆操作的所有记录save c:\sql.sql;保存sql脚本可以使 ...
- Windows Phone App Studio发布
Windows Phone App Studio发布重要更新-支持Windows 8.1 源代码生成 自2013年8月Apps Team发布Windows Phone App Studio以来,由于其 ...
- C程序设计语言(第二版)习题:第一章
第一章虽然感觉不像是个习题.但是我还是认真去做,去想,仅此而已! 练习 1-1 Run the "hello, world" program on your system. Exp ...
- lnmp1.0 升级php.5.4.28 后出错 Nginx 502 Bad Gateway
碰到一个很奇怪的问题,用lnmp自带的./upgrade_php.sh升级 php5.4.27正常.但升级到php5.4.28就出错,访问p.php 提示:Nginx 502 Bad Gateway. ...
- Sparse Filtering
Sparse Filtering 当前很多的特征学习(feature learning)算法需要很多的超参数(hyper-parameter)调节, Sparse Filtering则只需要一个超参数 ...
- 用django搭建一个简易blog系统(翻译)(三)
06. Connecting the Django admin to the blog app Django 本身就带有一个应用叫作Admin,而且它是一个很好的工具 在这一部分,我们将要激活admi ...
- web form中自定义HttpHandler仿mvc
web form中自定义HttpHandler仿mvc 前言 在mvc大行其道的今天,仍然有不少公司的项目还是使用web form来实现的(其实mvc也是基于web form的),如果要在项目中引入m ...
- d指针在Qt上的应用及实现
Qt为了使其动态库最大程度上实现二进制兼容,引入了d指针的概念.那么为什么d指针能实现二进制兼容呢?为了回答这个问题,首先弄清楚什么是二进制兼容?所谓二进制兼容动态库,指的是一个在老版本库下运行的程序 ...
- [学习笔记] TensorFlow 入门之基本使用
整体介绍 使用 TensorFlow, 你必须明白 TensorFlow: 使用图 (graph) 来表示计算任务. 在被称之为 会话 (Session) 的上下文 (context) 中执行图. 使 ...