小编Ale*_*lls的帖子

NSI映像到Base64

我需要创建一个NSImage可可对象的base64字符串表示.处理这个问题的最佳方法是什么,苹果文档似乎有点简短(或者我找不到).Base64编码从外部看起来相当复杂.

任何帮助将非常感谢.

干杯亚历克斯

编辑

NSArray *keys = [NSArray arrayWithObject:@"NSImageCompressionFactor"];
NSArray *objects = [NSArray arrayWithObject:@"1.0"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

NSImage *image = [[NSImage alloc] initWithContentsOfFile:[imageField stringValue]];
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithData:[image TIFFRepresentation]];
NSData *tiff_data = [imageRep representationUsingType:NSPNGFileType properties:dictionary];

NSString *base64 = [tiff_data encodeBase64WithNewlines:NO];
Run Code Online (Sandbox Code Playgroud)

cocoa base64

6
推荐指数
1
解决办法
4128
查看次数

标签 统计

base64 ×1

cocoa ×1