iOS - save image in jpg format

前端 未结 2 1828
不知归路
不知归路 2021-01-18 20:09

My question is what format the image is saved, if is dat or jpg. This is the code that i used:

    NSString * urlImage = .....;
    NSString * _folderPath =          


        
2条回答
  •  粉色の甜心
    2021-01-18 20:39

    Following is piece of code for save .jpg image

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *docs = [paths objectAtIndex:0];
    NSString* path =  [docs stringByAppendingFormat:@"/image1.jpg"];
    
    NSData* imageData = [NSData dataWithData:UIImageJPEGRepresentation(imageView.image, 80)];
    NSError *writeError = nil;
    [imageData writeToFile:path options:NSDataWritingAtomic error:&writeError];
    

提交回复
热议问题