Decode Base-64 encoded PNG in an NSString

前端 未结 6 1352
灰色年华
灰色年华 2020-11-30 13:00

I have some NSData which is Base-64 encoded and I would like to decode it, I have seen an example that looks like this

NSData* myPNGData = [xmlS         


        
6条回答
  •  生来不讨喜
    2020-11-30 13:48

    This will work for ios7 and above.

    - (UIImage *)decodeBase64ToImage:(NSString *)strEncodeData {
      NSData *data = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters];
      return [UIImage imageWithData:data];
    }
    

    And use the code like this:

    UIImage *img = [self decodeBase64ToImage:];
    

提交回复
热议问题