首页 文章

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

提问于
浏览
3

这个问题在这里已有答案:

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

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

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

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

2 回答

  • 5

    请尝试以下代码:

    UIImage *img; // Your image coming from server
    NSData *pngData = UIImagePNGRepresentation(img); // Convert it in to PNG data
    UIImage *pngImage = [UIImage imageWithData:pngData]; // Result image
    
  • 9

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

    NSData *imageData = UIImagePNGRepresentation(image);
    [imageData writeToFile:savedImagePath atomically:YES];
    

    答案取自here

相关问题