today my task is convert byte array to image
First I try to convert image to byte array :-
For converting Image to Byte array first we have to do is to convert
First, you need to convert bytes to NSData
NSData *imageData = [NSData dataWithBytes:bytesData length:length];
Then, convert the data back to image.
UIImage *image = [UIImage imageWithData:imageData];
And I suggest you should first searching about the documentations when problems occur.
Here is all:
UIImage *image = [UIImage imageNamed:@"RAC.png"];
NSData *imageData = UIImagePNGRepresentation(image);
// UIImageJPGRepresentation also work
NSInteger length = [imageData length];
Byte *byteData = (Byte*)malloc(length);
memcpy(byteData, [imageData bytes], length);
NSData *newData = [NSData dataWithBytes:byteData length:length];
UIImage *newImage = [UIImage imageWithData:newData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:newImage];
imageView.frame = CGRectMake(50, 50, 100, 100);
[self.view addSubview:imageView];