kumar
kumar

Reputation: 453

How to encode the image into string format?

I am trying to encode an image by using the below code, but the encoded data is not correct.

I am writing the code here. How can I change my code and get the correct encoded data?

NSData *imageData = UIImageJPEGRepresentation(myimages.image, 90);
// NSData *encrypteddata = [imageData dataUsingEncoding:NSASCIIStringEncoding];
NSString *encodedImage = [Base64 encode:imageData];
NSLog(@"my encoded image is 6666%@",encodedImage);

It prints bulk data. And whenever I pass this code into URL an blank image is displayed instead of the original image.

Upvotes: 0

Views: 2189

Answers (1)

To see if your Base64 encoded image string is correct, and would display as an image, on the server, do the following.

Within an HTML page, add the following.

<html>
    <image src="Base64 data here"/>
</html>

Upvotes: 1

Related Questions