如何将jpg图像转换为来自服务器的png图像

mad*_*dhu 3 iphone objective-c ios

嗨,任何人都可以帮助将从服务器获取的jpg图像转换为objective-c中的png图像.

实际上问题是通过应用程序,我们在Facebook上共享图像,但当jpg图像在服务器上传时,图像不在Facebook中共享.

UIImage*image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageurl]]];

我必须将imageurl转换为png格式.

Ash*_*osh 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
Run Code Online (Sandbox Code Playgroud)


yak*_*ali 5

在您检索图像/网址后,以这种方式保存它们:

NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
Run Code Online (Sandbox Code Playgroud)

答案取自这里