iOS how to convert bytes array to image

MacccUser

macrumors newbie
Original poster
Mar 19, 2014
3
0
hello ! I've converted UIImage to bytes array.
Code:
 NSString* filePath = [[NSBundle mainBundle] pathForResource:@"point" ofType:@"jpg"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    unsigned char *bytesArray = data.bytes;
    NSUInteger lengthOfBytesArray = data.length;
    
     NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:data.length];
    if (data.length>0)
    {
       
        NSUInteger i = 0;
        for (i = 0; i<data.length; i++) {
            [array addObject:[NSNumber numberWithUnsignedChar:bytesArray[i]]];

         
        }
    }

Now i need it back, I have no idea what should i do. Thanks )))
 

ianray

macrumors 6502
Jun 22, 2010
452
0
@
hello ! I've converted UIImage to bytes array.
Where's the UIImage?

You have converted an image file to an NSMutableArray containing data.length NSNumber objects. Is that really what you want?

Now i need it back, I have no idea what should i do. Thanks )))
What do you mean by "need it back"?
 

JohnsonK

macrumors regular
Mar 6, 2014
142
0
Something like this?

Code:
UIImage *img = [UIImage imageWithData:[NSData dataWithBytes:data.bytes length:data.length]];
 

ianray

macrumors 6502
Jun 22, 2010
452
0
@
What makes you think it is empty? If you tell us how you established that, we might be able to help :)
 

xStep

macrumors 68020
Jan 28, 2003
2,005
99
Less lost in L.A.
MacccUser, you should explan why you are doing this. Frankly, I can't think of a reason of converting an image to array of objects and back. When processing images manually, you acces the bytes directly via lower level methods.
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
MacccUser, you should explan why you are doing this. Frankly, I can't think of a reason of converting an image to array of objects and back. When processing images manually, you acces the bytes directly via lower level methods.
If the slab ended up at the pointer ByteArray, he could have done anything with it up to and including rotating bytewise or bitwise, inverting bits, etc.
Code:
unsigned char *bytesArray = data.bytes;
EDIT,, it looks like he's reading data from file because you're not supposed to be able to access data in an iOS UIImage object.
But it looks like a funny array of arrays being created instead of a C array.
 
Last edited:

xArtx

macrumors 6502a
Mar 30, 2012
764
1
It's hard to see what you're trying to do.
I have code to share that will check your inbox for a bitmap,
then determine the size and resolution from the bitmap header,
then load that file's image data to a C array (and a UIImage for display only).
It then encrypts or decrypts the image data only (not the header)
using the first ten digits of the currently selected song title in iPod.
Then writes back to file with the original bitmap header for email out.
https://www.youtube.com/watch?v=HUx9w4gyQ5c
bushprogrammer at the google email.
Don't ask me to explain it though!
 
Last edited by a moderator: