我用以下方法通过串行端口将收据直接打印到POS打印机上。 串行端口=new serial port (' com6',9100,Parity.None,8,StopBits.One );
port.Open (;
port.write(sometext );
port.Close (;
我的问题是,用上述方法打印位图图像吗? 感谢任何援助。
我还没有决定用微软pos for.net。 太慢了,打印机初始化需要时间,所以客户不喜欢等待。
谢谢你。
这应该会检索可以从位图发送到打印机的字符串。
公共字符串获取日志(
{
string logo=' ';
if (! file.exists (@ ' c : (bitmap.BMP ' ) )
返回空值;
BitArray dots=data.Dots;
byte [ ] width=bit converter.getbytes (data.width );
int offset=0;
binarywrite rbw=newbinarywriter (流;
bw.write((char )0x1B );
bw.write('@ ';
bw.write((char )0x1B );
宝马. write ('3);
bw.write((byte ) 24;
while(offsetdata.height ) )。
{
bw.write((char )0x1B );
bw.write('* );//位图像模式
bw.write () byte ) 33; //24-Double-density
bw.write(width[0]; //width low byte
bw.write(width[1]; //width高字节
for(intx=0; x数据. width; x )
{
for(intk=0; k 3; k )
{
字节片=0;
for(intb=0; b 8; b )
{
inty=() ) offset/8 ) k ) * 8) b;
//calculatethelocationofthepixelwewantinthebitarray。
//it'llbeat(y*width ) x。
intI=(y*data.width ) x;
//iftheimageisshorterthan 24 dots,pad with zero。
bool v=false;
if(Idots.length ) ) )。
{
v=dots[i];
}
slice|=(byte ) ) ) v? 1 : 0) (7 - b );
}
bw.write(slice;
}
}
offset =24;
bw.write((char )0x0A );
}
//restorethelinespacingtothedefaultof 30 dots。
bw.write((char )0x1B );
宝马. write ('3);
bw.write () byte ) 30;
bw.Flush (;
byte[] bytes=stream.ToArray (;
returnlogoencoding.default.getstring (bytes );
}
publicbitmapdatagetbitmapdata (字符串bmpfilename ) )。
{
using(varbitmap=(bitmap ) bitmap.from file (BMP filename ) )
{
var threshold=127;
var索引=0;
双多重=570; //thisdependsonyourprintermodel.forbeiyangyoushoulduse 1000
doublescale=(双精度) multiplier/(双精度) bitmap.Width;
intxheight=(int ) ) bitmap.Height * scale;
intxwidth=(int ) ) bitmap.Width * scale;
var dimensions=xwidth * xheight;
vardots=newbitarray(dimensions;
for(vary=0; y xheight; y )
{
for(varx=0; x xwidth; x )
{
var_x=(int ) ) x/scale;
var_y=(int ) ) y/scale;
varcolor=bitmap.getpixel(_x,_y );
varluminance=(int ) ) color.r * 0.3 color.g * 0.59 color.b * 0.11 );
dots [索引]=(luminance threshold;
索引;
}
}
返回新bitmapdata (
{
Dots=dots,height=(int () bitmap.Height*scale ),width=(int ) ) bitmap.Width*scale )。
(;
}
}
公共课堂幽默铅笔/p {
公共二进制文档
{
获取;
set;
}
公共int height
{
获取;
set;
}
公共插入宽度
{
获取;
set;
}
}