UIImagePNGRepresentation ..... writeToFile 始终是横向的

发布于 2024-11-15 16:39:44 字数 221 浏览 0 评论 0原文

每次我用相机拍照,然后保存时,图像总是横向的。这意味着我的 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 ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终止放荡 2024-11-22 16:39:44

我发现这篇文章非常有帮助,它描述了在保存图像之前向 UIImage 添加一个类别以进行图像旋转:

http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

然后一旦类别被实现,你就会做一些事情像这样:

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

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文