UIImage to base64 String Encoding

后端 未结 7 1709
囚心锁ツ
囚心锁ツ 2020-12-01 01:04

How to convert UIimage to base64 encoded string? I couldn\'t find any examples or codes with detailed regarding.

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 01:26

    I wonder why didn't you find your question because it's a very old question & can be found here.

    Anyways, You need to first add NSData categories to your project which are available from here -

    header and implementation Then convert your UIImage object into NSData the following way:

    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    

    And then apply Base64 encoding to convert it into a base64 encoded string:

    NSString *encodedString = [imageData base64Encoding];
    

提交回复
热议问题