UIImage存为本地文件,UIImage转换为NSData

UIImageView*imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(50,50,100,100)];

imageView.image= [UIImageimageNamed:@"11"];

//png格式

NSData*imagedata=UIImagePNGRepresentation(imageView.image);

//JEPG格式

//NSData *imagedata=UIImageJEPGRepresentation(m_imgFore,1.0);

NSArray*paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString*documentsDirectory=[pathsobjectAtIndex:0];

NSString*savedImagePath=[documentsDirectorystringByAppendingPathComponent:@"11.png"];

[imagedatawriteToFile:savedImagePathatomically:YES];

你可能感兴趣的:(UIImage存为本地文件,UIImage转换为NSData)