角度 – 在Custom TG2480H打印机上打印徽标
发布时间:2020-12-17 07:16:03 所属栏目:安全 来源:网络整理
导读:我正在使用Custom TG2480-H打印机打印收据.除了徽标外,我已收到所有收据. 我有一个单色的.bmp文件,代表徽标,并具有正确的尺寸. 我正在使用不同的响应类型检索文件: this.http.get('/assets/images/brand/logo-bnw.bmp',{ responseType: ResponseContentType
我正在使用Custom TG2480-H打印机打印收据.除了徽标外,我已收到所有收据.
我有一个单色的.bmp文件,代表徽标,并具有正确的尺寸. 我正在使用不同的响应类型检索文件: 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',{ 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,62,40,120,56,1,14,65533…] ArrayBuffer bytes (479) [19778,958,896,3780,65535,255,65535…] 这些似乎都是错误的,Blob字节的数量太低,而其他两个都包含大于字节的数字(> 255). 我已经尝试将这些字节发送到打印机,并提出以下内容: > Blob什么都不打印 编辑:尝试添加’content-type’:’image / bmp’标题: 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,65533…] 看起来与文本响应相同 解决方法
您正在对所有返回类型使用response.text().对于二进制数据,您应该将其保留为blob.您可以通过使用来访问基础字节而无需转换为文本
response.arrayBuffer() 这应该给你正确的字节数组,你期待. 这个问题也很重要:Get Image or byte data with http 最佳答案采取的做法: var blob = new Blob([new Uint8Array(response._body)] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 套接字 – Pycharm Docker Unix / TCP套接字(使
- scala – 在Spark SQL中连接两个DataFrame并仅选
- Bootstrap――25+ Best Bootstrap Editors &
- 动态更新AngularJS指令中的ion.rangeSlider ngMo
- angularjs – 如何判断是否使用Angular构建了Web
- bash – 输入和输出重定向到同一个文件
- 每日点滴之贰零零玖年捌月贰拾陆日
- angularjs – Spring Security REST和Angular
- 《AngularJS》--监听angularjs列表数据是否渲染完
- angularjs – Restangular:具有包含嵌入式数组的
热点阅读