【问题标题】:Transparent UIImage in iphone app's Document folderiphone应用程序的Document文件夹中的透明UIImage
【发布时间】:2012-03-07 20:19:53
【问题描述】:

由于我正在保存具有透明部分的图像,但在将其保存在 Document 文件夹中时,透明部分变为白色。

下面是代码......

NSData *dataPhoto = UIImageJPEGRepresentation(imageBigPhoto, 1.0);
        //NSData *dataPhoto = UIImagePNGRepresentation(imageBigPhoto);
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,  YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        NSString *fullPathWithFoldername=[documentsDirectory stringByAppendingFormat:@"/%@",[[NSUserDefaults standardUserDefaults]valueForKey:@"PhotoFolderName"]];

        //NSLog(@"%@",fullPathWithFoldername);

        NSString *fullPath = [fullPathWithFoldername stringByAppendingPathComponent:name];

        [dataPhoto writeToFile:fullPath atomically:YES];

【问题讨论】:

  • 我看到您已从 PNG 格式切换到 JPEG 格式。 PNG也有同样的问题吗?
  • JPEG 不做透明度。

标签: iphone uiimage document transparent uiimagejpegrepresentation


【解决方案1】:

JPEG 图像不支持透明度。 PNG 图像可以。

【讨论】:

    【解决方案2】:

    我想你已经评论了你的图像的 PNG 表示,JPEG 表示不保存透明度。只需启用您注释的代码并尝试。

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多