Epson 微型打印机打印 LOGO C#
由于项目需要使用EPSON微型打印机打印LOGO,在网上查看了很多都是安装驱动然后设置打印机图片。
项目需要使用Bytes发送流,最后在网上找到了一些资料,记录下来方便自己和其他人使用。
public byte[] GetLogo(string LogoPath)
{
List<byte> byteList = new List<byte>();
if (!File.Exists(LogoPath))
return null;
BitmapData data = GetBitmapData(LogoPath);
BitArray dots = data.Dots;
byte[] width = BitConverter.GetBytes(data.Width); int offset = ;
MemoryStream stream = new MemoryStream(); //for (int i = 0; i < 12; i++)
//{
// byteList.Add(32); // 32 空格
//}
// BinaryWriter bw = new BinaryWriter(stream); // 初始化指令
byteList.Add(Convert.ToByte(Convert.ToChar(0x1B)));
// 图片居中指令
byteList.Add();
byteList.Add();
//bw.Write((char));
byteList.Add(Convert.ToByte('@'));
//bw.Write('@');
byteList.Add(Convert.ToByte(Convert.ToChar(0x1B)));
// bw.Write((char)0x1B);
byteList.Add(Convert.ToByte(''));
//bw.Write('3');
//bw.Write((byte)24);
byteList.Add((byte));
while (offset < data.Height)
{
byteList.Add(Convert.ToByte(Convert.ToChar(0x1B)));
byteList.Add(Convert.ToByte('*'));
//bw.Write((char)0x1B);
//bw.Write('*'); // bit-image mode
byteList.Add((byte));
//bw.Write((byte)33); // 24-dot double-density
byteList.Add(width[]);
byteList.Add(width[]);
//bw.Write(width[0]); // width low byte
//bw.Write(width[1]); // width high byte for (int x = ; x < data.Width; ++x)
{
for (int k = ; k < ; ++k)
{
byte slice = ;
for (int b = ; b < ; ++b)
{
int y = (((offset / ) + k) * ) + b;
// Calculate the location of the pixel we want in the bit array.
// It'll be at (y * width) + x.
int i = (y * data.Width) + x; // If the image is shorter than 24 dots, pad with zero.
bool v = false;
if (i < dots.Length)
{
v = dots[i];
}
slice |= (byte)((v ? : ) << ( - b));
}
byteList.Add(slice);
//bw.Write(slice);
}
}
offset += ;
byteList.Add(Convert.ToByte(0x0A));
//bw.Write((char));
}
// Restore the line spacing to the default of 30 dots.
byteList.Add(Convert.ToByte(0x1B));
byteList.Add(Convert.ToByte(''));
//bw.Write('3');
byteList.Add((byte));
return byteList.ToArray();
//bw.Flush();
//byte[] bytes = stream.ToArray();
//return logo + Encoding.Default.GetString(bytes);
}
public BitmapData GetBitmapData(string bmpFileName)
{
using (var bitmap = (Bitmap)Bitmap.FromFile(bmpFileName))
{
var threshold = ;
var index = ;
double multiplier = ;//570 // this depends on your printer model. for Beiyang you should use 1000
double scale = (double)(multiplier / (double)bitmap.Width);
int xheight = (int)(bitmap.Height * scale);
int xwidth = (int)(bitmap.Width * scale);
var dimensions = xwidth * xheight;
var dots = new BitArray(dimensions); for (var y = ; y < xheight; y++)
{
for (var x = ; x < xwidth; x++)
{
var _x = (int)(x / scale);
var _y = (int)(y / scale);
var color = bitmap.GetPixel(_x, _y);
var luminance = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
dots[index] = (luminance < threshold);
index++;
}
} return new BitmapData()
{
Dots = dots,
Height = (int)(bitmap.Height * scale),
Width = (int)(bitmap.Width * scale)
};
}
}
public class BitmapData
{
public BitArray Dots
{
get;
set;
} public int Height
{
get;
set;
} public int Width
{
get;
set;
}
}
使用以上代码就可以在EPSON等微型打印机上打印LOGO。
可以参考一下博客的打印指令,根据实际情况进行调整。
https://blog.csdn.net/kenneth95/article/details/54341887
Epson 微型打印机打印 LOGO C#的更多相关文章
- 吉特仓库管理系统-.NET打印问题总结
在仓储系统的是使用过程中避免不了的是打印单据,仓库系统中包含很多单据:入库单,出库单,盘点单,调拨单,签收单等等,而且还附带着很多的条码标签的打印.本文在此记录一下一个简单的打印问题处理方式.处理问题 ...
- 飞鹅云打印 API_C#
飞鹅云打印: 提交订单支付成功后台自动打印,实现无人销售,自动打印,后台统计打印记录功能: 有自带WIFY:连接到wify就可以打印小票: 有自动SIM卡:第1年免流量费,第2年30一年 ...
- soul开源网关项目搭建学习
1. soul开源网关项目搭建学习 1.1. 地址 https://gitee.com/shuaiqiyu/soul 1.2. 介绍 官方介绍:这是一个异步的,高性能的,跨语言的,响应式的API网关. ...
- springboot2.1.3.RELEASE+jsp笔记war部署tomcat
springboot+jsp <packaging>war</packaging> <parent> <groupId>org.springframew ...
- Redis(3) 配置文件 redis.conf
Redis.conf 配置详解: # Redis configuration file example. # # Note that in order to read the configuratio ...
- Selenium入门6 操作元素,获取元素属性
取元素的text,属性get_attribute,标签名tag_name 操作元素:send_keys输入,click点击,submit提交,clear清除输入 状态判断:is_display,is_ ...
- Windows Server 2008在网络环境配置打印机
下面学习在Windows Server2008在网络环境搭建打印机服务器,打印机服务器也是很常用的,特别是在中大型企业里面,打印机数量比较多为方便管理,可以搭建一个打印机服务,这里介绍一下,本地打印机 ...
- 曹工说Redis源码(3)-- redis server 启动过程完整解析(中)
文章导航 Redis源码系列的初衷,是帮助我们更好地理解Redis,更懂Redis,而怎么才能懂,光看是不够的,建议跟着下面的这一篇,把环境搭建起来,后续可以自己阅读源码,或者跟着我这边一起阅读.由于 ...
- YoyoGo基于ASP.NET Core设计的Golang实现
YoyoGo YoyoGo 是一个用 Go 编写的简单,轻便,快速的 微服务框架,目前已实现了Web框架的能力,但是底层设计已支持. Github https://github.com/yoyofx/ ...
随机推荐
- 协程gevent
协程,利用线程在等待其他资源期间去执行其他的函数. gevent里面封装了greenlet,greenlet里面封装了yield. from gevent import monkey import g ...
- SpringCloud启动类指定扫描包路径
//如果这个启动类所在的包路径隐藏的很深,则需要指定扫描包.否则默认扫描启动类所在的子包路径下 @SpringBootApplication(scanBasePackages="com.jo ...
- 7.8 paint.c 程序
## 7.8 paint.c 程序 #include <stdio.h> #define COVERAGE 350 // 每罐尤其可刷的面积(单位:平方英尺) int main(void) ...
- 基于STM8的TIM定时器操作---STM8-第三章
1. 综述 STM8S提供三种类型的 TIM 定时器:高级控制型(TIM1).通用型(TIM2/TIM3/TIM5)和基本型定时器(TIM4/TIM6).它们虽有不同功能但都基于共同的架构.此共同的架 ...
- dns相关
一 用于dns, whois相关的网站 1 http://viewdns.info/iphistory 2 http://bgp.he.net/ 3 https://whois.aliyun.com/ ...
- WinSDK-键盘消息
一 参考url http://www.cnblogs.com/5iedu/p/4656178.html http://blog.csdn.net/yiyefangzhou24/article/deta ...
- List<Map<String, Object>>集合中获取某个key并转换为List<Integer>集合
package com.codyy.sso.controller.yuanqu; import java.util.ArrayList; import java.util.HashMap; impor ...
- Nginx设置防止IP及非配置域名访问
#设置IP或其它域名访问时返回500或304 server{ listen default; server_name _; ##标示空主机头 return ; } #设置IP或其它域名访问时重定向到w ...
- Tomcat修改service.xml性能调优 增加最大并发连接数
详细配置: <Connector executor="tomcatThreadPool" port="80" protocol ...
- Python中文繁简体转换工具
Openccpy ___ _____ __ ___ ___ ___ _____ __ __ / __`\/\ '__`\ /'__`\/' _ `\ /'___\ /'___\/\ '__`\/\ \ ...