开发者

Converting Image to Byte Array

I am looking to convert a signature that is captured from the user.

I have the following

NSData *imageData = UIImagePNGRepresentation(drawImage.image);
    NSUInteger len = [imageData length];
    byteData = (Byte*)malloc(len);
    memcpy(byteData, [imageData bytes], len);

Which I saw from a similar question, My problem is I can't use byteData anywhere, it shoots back a Bad_access error. E Am I converting it properly to a byte Array? If I output imageData to console i get

<89504e47 0d0a1a0a 0000000d 49484452 00000140 0000016f 08060000 003b6a12 49000020 00494441 547801ed 9d07b464 4599c71d 494a5219 5832c210 84251d19 51118519 755d0c18 402489a0 b206c015 44443d0a a8e82a8a 804a7005 040cc0c2 022eac89 a30c02a3 4bf02c41 24391266 605601c9 9267ffff 377d39df f474bfd7 affb7657 75d7afce f9dead9b eaabfa7d f7febb6e ddf0a62c 58b0e079 24084000 02251278 7e898da6 cd108000 044c0001 e4388000 048a2580 0开发者_如何学JAVA0161b7a 1a0e0108 20801c03 108040b1 0410c062 434fc321 00010490 63000210 28960002 586ce869 38042080 00720c40 0002c512 40008b0d 3d0d8700 0410408e 010840a0 58020860 b1a1a7e1 10800002 c8310001 08144b00 012c36f4 341c0210 40003906 20008162 092080c5 869e8643 00020820 c7000420 502c0104 b0d8d0d3 70084000 01e41880 00048a25 8000161b 7a1a0e01 0820801c 03108040 b10410c0 62434fc3 21000104 90630002 10289600 02586ce8 69380420 8000720c 400002c5 1240008b 0d3d0d87 00041040 8e010840 a0580208 60b1a1a7 e1108000 02c83100 0108144b 00012c36 f4341c02 10400039 06200081 62092080 c5869e86 43000208 20c70004 20502c01 04b0d8d etc..


To convert data to string use:

[NSString stringWithCString: encoding:];
[NSString stringWithUTF8String:];

If you want to send it via HTTP use the second one. And make sure it is zero-terminated:

byteData = (Byte*)calloc(len+1, sizeof(Byte));


Solved it. Problem was i was encoding it with the format. I need to do a base64 Encoding. The following the site was was where the answer for the base64 encoder is http://www.cocoadev.com/index.pl?BaseSixtyFour

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜