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

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

    imageView.image = [UIImage imageNamed:@"11"];

    //png格式

    NSData *imagedata=UIImagePNGRepresentation(imageView.image);

    //JEPG格式

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

    

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

    NSString *documentsDirectory=[paths objectAtIndex:0];

    

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

    

    [imagedata writeToFile:savedImagePath atomically:YES];

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