objective c - Signed byte array to UIImage -


i trying display picture byte-array produced web service. printing out description looks this: ("-119",80,78,71,13,10,26,10,0,0,0,13,3 ... ) header clear it's png encoded in signed integers. __nscfarray having __nscfnumber elements.

my code in objective-c (based on googling):

nsdata *data = [nsdata datawithbytes:(const void *)myimagearray length [myimagearray count]]; uiimage *arrayimage = [uiimage imagewithdata:data]; 

i receive null uiimage pointer. tried converting unsigned nsnumbers first , passing nsdata, though perhaps did not correctly. doing wrong?

you cannot cast nsarray of nsnumber binary data. both nsarray , nsnumber objects; have own headers , internal structure not same original string of bytes. you'll need convert byte-by-byte along these lines:

nsarray *bytes = @[@1, @2, @3]; nsmutabledata *data = [nsmutabledata datawithlength:bytes.count]; (nsuinteger = 0; < bytes.count; i++) {     char value = [bytes[i] charvalue];     [data replacebytesinrange:nsmakerange(i, 1) withbytes:&value]; } 

char signed int8_t, appears kind of data you're working with. used mean "an ascii character," in c commonly used mean "byte."


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -