如何让本地.png图片转为base64字符串
How to let local .png image convert to base64 string
我尝试将我的 png 图像转换为 base64 字符串。
但是我在 consolog 中使用我的输出 base64 字符串并粘贴到在线工具网站。
它只显示图像的顶部,而不是完整的图像。
我的代码有什么问题?
UIImage *uiImageInstance = [[UIImage alloc] initWithContentsOfFile: filePath];
NSData *data = UIImagePNGRepresentation(uiImageInstance);
NSString *base64Str = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSLog(@"base64Str : %@", base64Str);
使用此代码:
NSData *imageData = UIImagePNGRepresentation(image);
NSString * base64String = [imageData base64EncodedStringWithOptions:0];
希望对您有所帮助。
我尝试将我的 png 图像转换为 base64 字符串。
但是我在 consolog 中使用我的输出 base64 字符串并粘贴到在线工具网站。
它只显示图像的顶部,而不是完整的图像。
我的代码有什么问题?
UIImage *uiImageInstance = [[UIImage alloc] initWithContentsOfFile: filePath];
NSData *data = UIImagePNGRepresentation(uiImageInstance);
NSString *base64Str = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSLog(@"base64Str : %@", base64Str);
使用此代码:
NSData *imageData = UIImagePNGRepresentation(image);
NSString * base64String = [imageData base64EncodedStringWithOptions:0];
希望对您有所帮助。