gpt4 book ai didi

iOS - 以jpg格式保存图像

转载 作者:可可西里 更新时间:2023-11-01 04:41:45 45 4
gpt4 key购买 nike

我的问题是图片保存的格式是dat还是jpg。这是我使用的代码:

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

NSString * imageName = [[urlImage componentsSeparatedByString:@"/"] lastObject];
NSString * jpegPath = [NSString stringWithFormat:@"%@%@",_folderPath,imageName];

if (![[NSFileManager defaultManager] fileExistsAtPath:jpegPath])
{
NSURL *url = [NSURL URLWithString:urlImage];
//Download image
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];

//Save image
NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];//1.0f = 100% quality
[data writeToFile:jpegPath atomically:YES];
}

最佳答案

下面是保存.jpg图片的一段代码

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];

关于iOS - 以jpg格式保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21677644/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com