I tried the solution given here using:
- (NSString *)encodeToBase64String:(UIImage *)image {
return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
The encoded string I am getting is different from the one I can get via uploading an image on web tool like.
Simply my string is different from web and is not able to decode on the web for an image.
my other implementation is
-(NSString*)base64StringForImage{
UIImage *originalImage =_image_PreviewImage.image;
UIGraphicsBeginImageContext(originalImage.size);
[originalImage drawInRect:CGRectMake(0, 0, 1000, 1000)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgData=UIImagePNGRepresentation(newImage);
NSString *base64String = [imgData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
return base64String;
}
originalImage and newImage both have the images. testing out reducing the image sizes
the option with
NSDataBase64EncodingEndLineWithLineFeed
given encoded string with half image like the below