Reputation: 665
I searched high and low for the past week, none of the similar questions on SO has solved my problem.
I'm trying to upload a UIImage to a .NET wcf (wsdl?). It needs to be in the form of a byte array.
I tried
NSData *data = [[NSData alloc]initWithData:UIImageJPEGRepresentation(Image, 1)];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data bytes], len);
and byteData returns
ˇÿˇ‡
That doesn't look like a byte array I'm sure. What does a byte array suppose to look like? I also tried called NSData description, and various others with no success.
I also tried
[self.imageFile base64EncodedStringWithOptions:NSDataBase64EncodingEndLineFeed];
and get back
/9j/4AAQSkZJRgABAQEAJAAkAAD/4QCMRXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAAAkA
Is that what a byte array suppose to look like? I would guess a byte array is suppose to look like the following.
[244, 22, 244, 4, 32, etc.....]
The byte array needs to be embedded in an XML. Any help is appreciated. Thanks!
Upvotes: 1
Views: 637
Reputation: 857
I think better approach will be if you will use Base64 Encoding .
Upvotes: 0
Reputation: 131426
The code you posted will convert a UIImage to a binary JPEG image in an NSData object, then extract the byte values from the NSData. That IS a byte array. (A block of memory containing bytes of binary data.)
It sounds like what you really want to do is format your binary data in XML format. That is a different question.
I did a Google search on "How do you represent binary data in XML" and it seems that Base64 encoding is the consensus. I suggest you look into Base64 encoding.
Upvotes: 1