UIImagePNGRepresentation ..... writeToFile总是风景 [英] UIImagePNGRepresentation ..... writeToFile is always landscape
问题描述
每次我使用相机拍摄照片,然后保存它,图像总是在风景中。这意味着我的Xib中的UIImageView是错误的。它的肖像 - 这是我想要和期望的。我可以通过将图像旋转90度来纠正这个问题,但即使这样我也无法禁用动画,该动画显示原始风景照片,然后是动画旋转本身。如何确保来自相机的UIImageView在保存时实际上处于纵向模式而不是横向模式,如何在CGAffineTranformationMakeRotation期间禁用动画?
Each time I use the camera to take a photograph, then save it the image is always in landscape. This means the UIImageView in my Xib is the wrong way around. Its Portrait - which is what I want and expected. I can correct this by rotating the image 90 degrees but even then I can't disable the animation which shows the original landscape photo followed by the animated rotation itself. How can I ensure the UIImageView from the camera is actually in portrait mode when saved and not landscape and, how can I disable the animation during the CGAffineTranformationMakeRotation ??
推荐答案
我发现这篇文章非常有用,它描述了在UIImage中添加一个类别来做你之前的图像旋转保存它:
I found this post to be very helpful, it describes adding a category to UIImage to do the rotation of the image before you save it:
http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/
然后一旦类别实现,你会做这样的事情:
And then once the category is implemented, you would do something like this:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage, *editedImage, *rotatedImage;
editedImage = (UIImage *)[info objectForKey:UIImagePickerControllerEditedImage];
originalImage = (UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage];
if (editedImage)
{
rotatedImage = [editedImage rotate:UIImageOrientationRight];
}
else
{
rotatedImage = [originalImage rotate:UIImageOrientationRight];
}
NSString *f = @"/set/this/to/your/file/name";
[UIImagePNGRepresentation(rotatedImage) writeToFile:f atomically:YES];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
这篇关于UIImagePNGRepresentation ..... writeToFile总是风景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!