I am developing an application in which I take an image in portrait mode and then switch to another class with image data and display that image in UIImageView on UIScrollView.
Now, if I take the image form library, it works fine, but if I need to capture an image, it will display the data in landscape mode. Below is my code for both classes .:
Grade 1:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSData *imgData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]); [picker dismissModalViewControllerAnimated:YES]; image = [[UIImage alloc] initWithData:imgData]; CGImageRef imgRefCrop = image.CGImage; UIImage *photo = [UIImage imageWithCGImage:imgRefCrop]; PhotoCropperPage *photoCropper = [[PhotoCropperPage alloc] initWithPhoto:photo delegate:self uiMode:PCPUIModePresentedAsModalViewController showsInfoButton:YES]; [photoCropper setMinZoomScale:0.3f]; [photoCropper setMaxZoomScale:4.0f]; [self.navigationController pushViewController:photoCropper animated:YES]; }
Grade 2:
- (void) loadPhoto { if (self.photo == nil) { return; } CGFloat w = self.photo.size.width; CGFloat h = self.photo.size.height; CGRect imageViewFrame = CGRectMake(0.0f, 0.0f, roundf(w / 2.0f), roundf(h / 2.0f)); self.scrollView.contentSize = imageViewFrame.size; UIImageView *iv = [[UIImageView alloc] initWithFrame:imageViewFrame]; iv.image = self.photo; [self.scrollView addSubview:iv]; self.imageView = iv; [iv release]; }
I donβt understand where I am making a mistake? Can anyone point me to? Thanks in advance.
source share