Closed jrr363 closed 9 years ago
I think you should check the image orientation of image, and rotate it according to the image orientation, then to save it. For example, if the image orientation of an image is UIImageOrientationDown, then it should be rotated by M_PI.
Yup yup you were definitely correct. Thank you! Below: I changed your 'saveBtnTapped' method a little to give the user the option to save with or without metadata.
(void)saveBtnTapped:(BOOL)metadata { CGAffineTransform transform = CGAffineTransformIdentity;
// translate CGPoint translation = [self.photoView photoTranslation]; transform = CGAffineTransformTranslate(transform, translation.x, translation.y);
// rotate transform = CGAffineTransformRotate(transform, self.photoView.angle);
// scale CGAffineTransform t = self.photoView.photoContentView.transform; CGFloat xScale = sqrt(t.a * t.a + t.c * t.c); CGFloat yScale = sqrt(t.b * t.b + t.d * t.d); transform = CGAffineTransformScale(transform, xScale, yScale);
CGImageRef imageRef = [self newTransformedImage:transform sourceImage:self.image.CGImage sourceSize:self.image.size sourceOrientation:self.image.imageOrientation outputWidth:self.image.size.width cropSize:self.photoView.cropView.frame.size imageViewSize:self.photoView.photoContentView.bounds.size];
NSData *imageData; //Data from some NSDictionary if (metadata == YES) { //Do something with data }
//if ([self.delegate respondsToSelector:@selector(finishWithCroppedImage:)]) { // [self.delegate finishWithCroppedImage:image]; //} if (self.autoSaveToLibray) { ALAssetsLibrary library = [[ALAssetsLibrary alloc] init]; if (metadata == NO) { NSLog(@"Should save without metadata"); ALAssetsLibrary library = [[ALAssetsLibrary alloc] init]; [library writeImageToSavedPhotosAlbum:imageRef metadata:nil completionBlock:^(NSURL assetURL, NSError error) { if (!error) { } }];
} else {
NSLog(@"Should save with metadata");
[library writeImageDataToSavedPhotosAlbum:imageData metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
if (!error) {
}
}];
}
}
[self dismissViewControllerAnimated:YES completion:nil];
Hi, I just add the api
[library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error) {
if (!error) {
}
}];
to save the orientation of the image
you have any ideas on why? Great project by the way love the simplicity!