온라인에서 모든 스택 오버플로 게시물 및 비디오를 조사 해본 결과 제대로 작동하는 솔루션을 찾을 수 없습니다. 현재 사용자는 AWS S3 버킷에 업로드하기 전에 압축 할 사진을 선택합니다. 업로드가 완벽하게 작동하지만 압축 된 이미지가 원래 이미지보다 큽니다. 예를 들어 사용자가 9KB 사진을 선택하면 S3에 업로드 할 때 사진은 28.5KB입니다. 나는 다른 사진을 시도했고 그것은 48KB이고 S3의 "압축"후에는 378.9KB! (모든 최신 소프트웨어 버전을 사용하고 시뮬레이터로 컴파일 중입니다.)iOS에서 이미지를 압축하는 방법?
업로드하기 전에 최대한 원본 이미지를 압축하고 싶습니다.
내가 이미지를 "압축"방법 :
이
내가 지금까지 무엇을 가지고//Convert product UIImage
NSArray *productImagePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *productImageFilePath = [[productImagePaths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@".png"]];
[UIImagePNGRepresentation(compressedProductImage) writeToFile:productImageFilePath atomically:YES];
NSURL *productImageFileUrl = [NSURL fileURLWithPath:productImageFilePath];
uploadRequest.body = productImageFileUrl;//Needs to be a NSURL
uploadRequest.bucket = AWS_BUCKET_NAME;
uploadRequest.key = productImageKey;
uploadRequest.contentType = @"image/png";
uploadRequest.ACL = AWSS3BucketCannedACLPublicRead;
[[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task) {
if (task.error != nil) {
NSLog(@"%s %@","Error uploading (product image):", uploadRequest.key);
}else{
NSLog(@"Product image upload completed");
}
return nil;
}];
그래서 그것은 모든 업로드하기 전에 이미지를 압축 복잡하거나하지 가치에 하나처럼 보인다. 나는 더 큰 이미지를 다루고 더 나은 캐싱 시스템에서 작업 할 것이라고 생각합니다. 통찰력있는 응답에 감사드립니다! –