iOS - save image in jpg format

前端 未结 2 1827
不知归路
不知归路 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:16

    You should use

    stringByAppendingPathComponent method to create or get exact valid path

    Use this way:

        NSString * jpegPath = [_folderPath stringByAppendingPathComponent:imageName];// [NSString stringWithFormat:@"%@%@",_folderPath,imageName];
    
    0 讨论(0)
  • 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];
    
    0 讨论(0)
提交回复
热议问题