My requirement is that a local image will be converted to a byte array and then the byte array is converted back to the image
i have done the image to Byte array conversion but i trying bytearray convert to image and then display on UIIMageView code is no error but Image Converted to byte array but byte array converted io image but image is not display please give me any idea
Here is what I have so far
UIImage *image = [UIImage imageNamed: @"shopper-home-copy_03.png"];
//Output
NSData *data = UIImagePNGRepresentation(image);
NSUInteger len = data.length;
uint8_t *bytes = (uint8_t *)[data bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:len * 3];
[result appendString:@"["];
for (NSUInteger i = 0; i < len; i++)
{
if (i)
{
[result appendString:@","];
}
[result appendFormat:@"%d", bytes[i]];
}
[result appendString:@"]"];
NSMutableData *newdata = [NSMutableData new];
NSScanner *theScanner = [NSScanner scannerWithString: result];
while ([theScanner isAtEnd] == NO) {
int a;
[theScanner scanInt:&a];
uint8_t b = a;
[newdata appendBytes:(const void *)&b length:1];
}
UIImage *newImage = [UIImage imageWithData:newdata];
self->imageView = [[UIImageView alloc] initWithImage:newImage];
imageView.frame = CGRectMake(0, 25 , 150,150);
[self.view addSubview:self->imageView];