objective c - I need to get array of bytes from image -


i'm trying byte array containing bytes of image, this:

nsstring* filepath = [[nsbundle mainbundle] pathforresource:@"image" oftype:@"png"]; nsdata *data = [nsdata datawithcontentsoffile:filepath]; unsigned char *bytesarray = data.bytes; nsuinteger lengthofbytesarray = data.length; 

next, try copy these values array.

    if (data.length>0)     {         nsmutablearray *array = [[nsmutablearray alloc] initwithcapacity:data.length];         (int = 0; i<data.length; i++) {             unsigned char bytefromarray = bytesarray[i];             [array addobject:[nsvalue valuewithbytes:&bytefromarray objctype:@encode(unsigned char)]];          }     } 

finally in debug received array of empty objects. have memory address don't have value (nsconcreatevalue type). in debug area i've checked bytefromarray , `(unsigned char)'p'. did choose wrong way byte array image, or code wrong?

try replacing

    (int = 0; i<data.length; i++) {         unsigned char bytefromarray = bytesarray[i];         [array addobject:[nsvalue valuewithbytes:&bytefromarray objctype:@encode(unsigned char)]];     } 

with this

    (int = 0; i<data.length; i++)          [array addobject:[nsnumber numberwithunsignedchar:bytesarray[i]]]; 

also, suggest adding nslog display data.length see how many elements being added array.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -