Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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 )))
 
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"?
 
Something like this?

Code:
UIImage *img = [UIImage imageWithData:[NSData dataWithBytes:data.bytes length:data.length]];
 
What makes you think it is empty? If you tell us how you established that, we might be able to help :)
 
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.
 
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:
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:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.