首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

UIImage封存到文件,PNG/JPEG自适应

2012-07-15 
UIImage保存到文件,PNG/JPEG自适应UIImage保存到文件,PNG/JPEG自适应+ (BOOL)writeImage:(UIImage*)image

UIImage保存到文件,PNG/JPEG自适应
UIImage保存到文件,PNG/JPEG自适应
+ (BOOL)writeImage:(UIImage*)image toFileAtPath:(NSString*)aPath

{
         if ((image == nil) || (aPath == nil) || ([aPathisEqualToString:@""]))
              return NO;

         @try
         {
              NSData *imageData = nil;
              NSString *ext = [aPath pathExtension];
              if ([ext isEqualToString:@"png"])

              {
                     imageData = UIImagePNGRepresentation(image);


              }
              else

              {
                     // the rest, we write to jpeg
                     // 0. best, 1. lost. about compress.
                     imageData = UIImageJPEGRepresentation(image,0);   
              }

              if ((imageData == nil) || ([imageData length] <= 0))
                     return NO;

              [imageData writeToFile:aPath atomically:YES];     

              return YES;
         }
         @catch (NSException *e)
         {
              NSLog(@"create thumbnail exception.");
         }

         return NO;
}
转自:http://www.cocoadev.cn/iPhone-iPad/iPhone-Uimage-Write-to-file.asp

热点排行