大家好,有没有人能帮忙在objective-c中将从服务器获取的jpg图像转换为png图像。
实际上问题出在应用程序分享图片到Facebook时,当上传jpg图像到服务器后,无法在Facebook上分享该图像。
下面是代码:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageurl]]];
我需要将图像的URL转换为png格式。
大家好,有没有人能帮忙在objective-c中将从服务器获取的jpg图像转换为png图像。
实际上问题出在应用程序分享图片到Facebook时,当上传jpg图像到服务器后,无法在Facebook上分享该图像。
下面是代码:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageurl]]];
我需要将图像的URL转换为png格式。
UIImage *img; // Your image coming from server
NSData *pngData = UIImagePNGRepresentation(img); // Convert it in to PNG data
UIImage *pngImage = [UIImage imageWithData:pngData]; // Result image
NSData *imageData = UIImagePNGRepresentation(image);
[imageData writeToFile:savedImagePath atomically:YES];
以下答案摘自这里
pngData
将为nil
。 - Dennis Pashkov