gpt4 book ai didi

angular - 在自定义 TG2480H 打印机上打印 Logo

转载 作者:太空狗 更新时间:2023-10-29 17:38:02 25 4
gpt4 key购买 nike

我正在使用 Custom TG2480-H 打印机打印收据。除了 Logo ,我的所有收据都有效。

我有一个单色 .bmp 文件,代表 Logo 并具有正确的尺寸。

我正在检索文件,使用不同的响应类型:

this.http.get('/assets/images/brand/logo-bnw.bmp', {
responseType: ResponseContentType.Blob
}).subscribe((response: Response) => {
console.log('Blob bytes', this.kiowarePrintService.getBytesFromText(response.text()));
});
this.http.get('/assets/images/brand/logo-bnw.bmp', {
responseType: ResponseContentType.Text
}).subscribe((response: Response) => {
console.log('Text bytes', this.kiowarePrintService.getBytesFromText(response.text()));
});
this.http.get('/assets/images/brand/logo-bnw.bmp', {
responseType: ResponseContentType.ArrayBuffer
}).subscribe((response: Response) => {
console.log('ArrayBuffer bytes', this.kiowarePrintService.getBytesFromText(response.text()));
});

这是关于 ResponseContentType 的文档以及它可以具有的不同值。

这是 getBytesFromText 的代码:

getBytesFromText(text: string) {
const bytes: number[] = [];
for (let i = 0; i < text.length; i++) {
bytes.push(text.charCodeAt(i));
}
return bytes;
}

将响应转换为字节打印这些值:

Blob bytes (2) [123, 125]

Text bytes (951) [66, 77, 65533, 3, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 40, 0, 0, 0, 120, 0, 0, 0, 56, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 65533, 3, 0, 0, 65533, 14, 0, 0, 65533, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533…]

ArrayBuffer bytes (479) [19778, 958, 0, 0, 0, 62, 0, 40, 0, 120, 0, 56, 0, 1, 1, 0, 0, 896, 0, 3780, 0, 3780, 0, 0, 0, 0, 0, 0, 0, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 255, 65535, 65535, 65535, 65535, 65535…]

这些似乎都是错误的,Blob 字节数太少,另外两个都包含大于字节数 (>255) 的数字。

无论如何,我已经尝试将这些字节发送到打印机并得出以下结论:

编辑:尝试添加 'content-type': 'image/bmp' header :

    const headers: Headers = new Headers({'Content-Type': 'image/bmp'});
const options: RequestOptions = new RequestOptions({headers: headers});
this.http.get('/assets/images/brand/logo-bnw.bmp', options).subscribe((response: Response) => {
console.log('image/bmp bytes', this.kiowarePrintService.getBytesFromText(response.text()));
});

记录这个:

image/bmp bytes (951) [66, 77, 65533, 3, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 40, 0, 0, 0, 120, 0, 0, 0, 56, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 65533, 3, 0, 0, 65533, 14, 0, 0, 65533, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 0, 65533, 65533, 65533, 65533, 65533, 65533…]

看起来和文本响应一样

最佳答案

您正在为所有返回类型使用 response.text()。对于二进制数据,您应该将其保存为一个 blob。您可以使用

访问底层字节而无需转换为文本
response.arrayBuffer()

这应该会为您提供您期望的正确字节数组。

这个问题也很相关:Get Image or byte data with http

最佳答案采用的方法是:

var blob = new Blob([new Uint8Array(response._body)]

关于angular - 在自定义 TG2480H 打印机上打印 Logo ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44802825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com