如何转换为十六进制的数组到一个UIImage? [英] How do I convert a hex array into a UIImage?

查看:284
本文介绍了如何转换为十六进制的数组到一个UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有涉及与P25mi,没有公认的答案动态打印图像的几个悬而未决的问题。下面几个链接。

<一个href=\"http://stackoverflow.com/questions/13838283/how-to-convert-image-to-bitmap-$c$c-for-bluetooth-print-in-iphone\">How图像转换为位图code在iphone蓝牙打印

<一个href=\"http://stackoverflow.com/questions/5879807/how-to-convert-image-into-hexa-decimal-bytes-array-to-send-it-to-output-stream-i\">How图像转换成十进制六字节数组将其发送到输出流中的iOS SDK

下code样本是硬$ ​​C $ CD工作的例子,它打印的静态图像p25mi。数组中的前10个元素都为P25控制和格式的命令。

我觉得下面的十六进制的数组转换成一个UIImage在一个UIImageView显示的可能棚上做相反的一些情况。

如何确定的高度,宽度和再$ P $图像下方的code样品中psented深度?

我如何下十六进制的数组转换成一个UIImage?

  unsigned char型buffer3 [796] = {
    将0x55,0x66,0x77,均为0x88,0x44进行,0x1B,将0x58,0X31,
    的0x19,0x20的,
    0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,为0x00,0x00时,为0x00,0x80的,为0x00,0x00时,为0x00,0x00时,为0x00,0x00时,为0x00,0x00时,为0x00,0x00时,为0x00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×01,将0xC0,为0x00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×01,0x80的,0×00,×03,0x60的,为0x00,0x00时,为0x00,0x00时,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,×03
    ,0XA0,为0x00,0x07执行,反0xB0,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×05,0x60的,为0x00,0x07执行,0xD8,为0x00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×05,0XA0,为0x00,0x13,0xEC,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×04
    ,为0x20,0x00时,0x29,0xF4中,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,×03,将0xC0,为0x00,0x64,0xF9,为0x00
    ,为0x0F,为0xFF,为0x9c,0×01,将0xC0,的0x19,0xFF的,将0xC0,0x7F的,0xFC有,0x7F的,0xF9,将0xC0,0x3D之间,为0xFF
    ,的0xf1,为0xFF,0xE3,0xFF的,将0xC0,为0x00,0x00时,0xF2(0x73)的,0x80的,为0x0F,为0xFF,为0x9c,0×01,将0xC0
    ,的0x19,0xFF的,将0xC0,0x7F的,0xFE时,0x7F的,是0xFD,取0xE0,0x3D之间,为0xFF,的0xf1,为0xFF,0xE3,0xFF的,将0xC0
    ,为0x00,0x00时,0x79的,0×26,将0xC0,为0x0F,0xFF的,的0xDC,0×01,将0xC0,的0x19,0xFF的,将0xC0,0x7F的,0xFE的
    ,为0xFF,是0xFD,0XF0,0x7D,为0xFF,0xFB的才能,为0xFF,0xF7,为0xFF,取0xE0,0×00,×03,0x3C符号,0x8F,0x60的
    ,的0x0C,0×01,的0xDC,0×01,将0xC0,的0x19,0x80的,为0x00,0x70,0x0E的,取0xE0,0x1D,0XF0,0x7D,0x80的
    ,0x3B,0x80的,0x77,0x00时,取0xE0,为0x00,0x04的0x9E,0x8F,反0xB0,为0x0E,0×01,的0xDC,0×01,将0xC0
    ,的0x19,0x80的,为0x00,0x70,0x0E的,取0xE0,0x1D,为0xF8的,是0xFD,0x80的,0x33,0x80的,0x77,0x00时,取0xE0
    ,0×00,为0x0E,0x4F,0×27,0xD8,为0x0F,为0xFF,为0x9c,0×01,将0xC0,的0x19,0xFF的,将0xC0,0x7F的,0xFC有
    ,取0xE0,0x1D,0xF9,是0xFD,为0xFF,0xF3,0x80的,0x77,0x00时,取0xE0,0x00时,为0x0F,值为0x26,0x53,0xC8
    ,为0x0F,为0xFF,为0x9c,0×01,将0xC0,的0x19,0xFF的,将0xC0,0x7F的,0xFC有,0xEF,是0xFD,0xDD,0xDD,为0xFF
    ,0xF3,0x80的,0x77,0x00时,取0xE0,为0x00,0x07执行,0×90,0xC9,0XF0,为0x0F,0xFF的,的0xDC,0×01,将0xC0
    ,的0x19,0xFF的,将0xC0,0x7F的,0xFE时,0xEF,是0xFD,0xDF,0x9D,为0xFF,0xFB的才能,0x80的,0x77,0x00时,取0xE0
    ,0×00,×03,0xC9,0xE4,取0xE0,的0x0C,0x00时的0xDC,0×01,将0xC0,的0x19,0x80的,为0x00,0x70,0×06
    ,0xE7,是0xFD,0xCF,0x9D,0x80的,0x3B,0x80的,0x77,0x00时,取0xE0,0×00,0×01,0XF0,0xF2,0X40
    ,为0x0E,0×01,的0xDC,为0x00,将0xC0,的0x19,0x80的,为0x00,0x70,0x0E的,取0xE0,0x1D,0xCF,0x1D,0x80的
    ,0x3B,0x80的,0x77,0x00时,取0xE0,为0x00,0x00时,0xE6,0x79的,0x00时,为0x0F,为0xFF,0xDF,0xFC有,为0xFF
    ,0xF9,为0xFF,将0xC0,0x7F的,0xFE时,取0xE0,0x1D,0xC7,0x1D,为0xFF,0xFB的才能,为0xFF,0xF7,为0xFF,取0xE0
    ,为0x00,0x00时,0x49,0x3D之间,为0x00,为0x0F,为0xFF,0x9F,0xFC有,为0xFF,0xF9,为0xFF,将0xC0,0x7F的,0xFE的
    ,取0xE0,0x1D,为0xC2,0x1D,0xFF的,的0xf1,为0xFF,0xE3,0xFF的,将0xC0,为0x00,0x00时,为0x1C,0x9E,为0x00
    ,为0x0F,为0xFF,0x1F的,0xFC有,0x7F的,0xE1,0xFF的,将0xC0,0x7F的,0xFC有,取0xE0,0x1D,将0xC0,0x1D,为0xFF
    ,取0xE0,0xFF的,0xC1,0xFF的,0x80的,为0x00,0x00时,0X1E,0x4C,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,为0x00,0x00时,为0x0F,为0x20,0x00时,为0x00,0x00时,为0x00,0x00时,为0x00,0x00时,为0x00,0x00时,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×07,0×90,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,×03,取0xE0,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×01,将0xC0,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0x80的,为0x00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00,0×00
    ,0×00,0×00,0×00
};


解决方案

有一个看的 P25开发指南V3.4.1

我不明白的前五个字符是。但是,下列字符的序列esacpe:

  0x1B,将0x58,0X31,的0x19,0x20的

他们是在横向模式下打印一个位图。的0x19和0x20的是水平尺寸(次8)和垂直尺寸分别。所以该图像是200由32像素。下面的25×32字节然后包含像素(黑色和白色,每个像素1位)。

我希望整件事是810字节长(5个字节不明,5个字节转义序列,25×32像素字节的数据)。我不明白为什么它有796的工作原理。

更新:

要一个UIImage转换成原始的黑白数据(没有转义序列),以下code应该有所帮助。我希望每像素的位图1位仍然受到支持。

  CGColorSpaceRef色彩= CGColorSpaceCreateDeviceGray();
为size_t bytesPerRow =(uiImage.size.width + 7)/ 8;
为size_t imageDataSize = uiImage.size.height * bytesPerRow;
无符号字符* imgData =(无符号字符*)malloc的(imageDataSize);
CGContextRef上下文= CGBitmapContextCreate(imgData,
    uiImage.size.width,uiImage.size.height,
    1,bytesPerRow,
    色彩,kCGImageAlphaNone);UIGraphicsPushContext(上下文);
[UIImage的drawInRect:CGRectMake(0.0,0.0,uiImage.size.width,uiImage.size.height)];
UIGraphicsPopContext();CGContextRelease(上下文);
CGColorSpaceRelease(色彩);的for(int i = 0; I&LT; imageDataSize;我++)
    imgData [I] =〜imgData [I];...图像(imgData)发送到打印机...免费(imgData);

There are several unanswered questions related to printing images dynamically with P25mi, none with accepted answers. A couple links below.

How to convert image to bitmap code for bluetooth print in iphone

How to convert image into hexa decimal bytes array to send it to output stream in iOS sdk

The code sample below is a hard-coded working example that prints a static image to p25mi. The first 10 elements in the array are control and format commands for the p25.

I think converting the hex array below into a UIImage displayable in a UIImageView might shed some light on doing the reverse.

How do I determine the height, width and depth of the image represented in the code sample below?

How do I convert the hex array below into a UIImage?

unsigned char buffer3[796]={
    0x55 ,  0x66 ,  0x77 ,  0x88 ,  0x44 ,  0x1B ,  0x58 ,  0x31 ,  
    0x19, 0x20, 
    0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 
    ,0x00 ,0x00 ,0x00 ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0xC0 ,0x00
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 
    ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x80 ,0x00 ,0x03 ,0x60 ,0x00 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.1.

I don't understand what the first five characters are for. But the following characters are an esacpe sequence:

 0x1B,  0x58,  0x31,  0x19, 0x20

They are for printing a bit-image in horizontal mode. 0x19 and 0x20 are the horizontal dimension (times 8) and the vertical dimension, respectively. So the image is 200 by 32 pixel. The following 25 x 32 bytes then contain the pixels (black and white, 1 bit per pixel).

I would expect the whole thing to be 810 bytes long (5 bytes unidentified, 5 bytes escape sequence, 25 x 32 bytes of pixel data). I don't quite understand why it works with 796.

Update:

To convert a UIImage into the raw black and white data (without the escape sequence), the following code should help. I hope 1 bit per pixel bitmaps are still supported.

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
size_t bytesPerRow = (uiImage.size.width + 7) / 8;
size_t imageDataSize = uiImage.size.height * bytesPerRow;
unsigned char* imgData = (unsigned char*) malloc(imageDataSize);
CGContextRef context =  CGBitmapContextCreate(imgData,
    uiImage.size.width, uiImage.size.height, 
    1, bytesPerRow, 
    colorSpace, kCGImageAlphaNone);

UIGraphicsPushContext(context);
[uiImage drawInRect: CGRectMake(0.0, 0.0, uiImage.size.width, uiImage.size.height)];
UIGraphicsPopContext();

CGContextRelease(context);
CGColorSpaceRelease(colorSpace);

for (int i = 0; i < imageDataSize; i++)
    imgData[i] = ~imgData[i];

... send the image (imgData) to the printer ...

free(imgData);

这篇关于如何转换为十六进制的数组到一个UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆