任何人都可以帮助将从服务器获取的jpg图像转换为objective-c中的png图像。
实际上问题是通过应用程序,我们在Facebook上共享图像,但是当jpg图像在服务器上传时,图像不会在Facebook中共享。
UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageurl]]];
我必须将imageurl转换为png格式。
答案 0 :(得分:9)
请尝试以下代码:
UIImage *img; // Your image coming from server
NSData *pngData = UIImagePNGRepresentation(img); // Convert it in to PNG data
UIImage *pngImage = [UIImage imageWithData:pngData]; // Result image
答案 1 :(得分:5)
检索图像/网址后以这种方式保存:
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
摘自here