Irrd Irrd - 4 months ago 47
Objective-C Question

How to convert UIImagePicker image into a byte array objective-c

I am selecting a

from image picker. Then I want to pass my selected image as a byte array to the server. so in this delegate I am getting the path of my selected image like this.

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info


Then convert into a byte array I do like this.

NSData *data = [NSData dataWithContentsOfURL:filePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data bytes], len);
NSLog(@"----BITE DATA----%@",byteData);

but this
always get nil. why is that? Please help me.


plz use this

  UIImage *Image = (UIImage*)[info valueForKey:UIImagePickerControllerOriginalImage];
        NSData *imgData = UIImageJPEGRepresentation(Image, 1); //1 it represents the quality of the image.
        NSLog(@"Size of Image(bytes):%d",[imgData length]);