【问题标题】:didFinishPickingMediaWithInfo orientation issuedidFinishPickingMediaWithInfo 方向问题
【发布时间】:2013-05-07 07:46:09
【问题描述】:

我正在尝试在imagePickerController:didFinishPickingMediaWithInfo 中管理图像旋转,但经过多次尝试,我没有找到任何解决方案。我的最后一次尝试是:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

        // load the storyboard by name
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[ApplicationSupport getStoryBoardName] bundle:nil];
        UploadViewController *uploadView = [storyboard instantiateViewControllerWithIdentifier:@"ViewUploadFile"];

        UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
        NSDictionary *metadataImage = [info valueForKey:UIImagePickerControllerMediaMetadata];

        uploadView.imageToUpload = image;

        if([[metadataImage objectForKey:@"Orientation"] intValue] == 3) {
            UIImage *imageRotated = [UIImage imageWithCGImage:[image CGImage] scale:[image scale] orientation:UIImageOrientationDown];
            uploadView.dataToUpload = UIImagePNGRepresentation(imageRotated);
        } else {
            uploadView.dataToUpload = UIImagePNGRepresentation(image);
        }

        // ETC...
    }

我不能也不想使用JPEGRepresentation。当 iPad 处于特定位置时,我需要将照片旋转 180°。

有什么想法吗?

【问题讨论】:

  • 您是否尝试过使用 UIImageOrientationLeft 或 UIImageOrientationRight 而不是 Dowm。它会旋转吗?
  • 经过几次尝试,我明白我不想改变方向“标志”。我需要“物理”旋转我的图像。所以我尝试了这个:UIGraphicsBeginImageContext(image.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRotateCTM(context, (90 * M_PI / 180)); [image drawAtPoint:CGPointMake(0, 0)]; UIImage *imageRotated = UIGraphicsGetImageFromCurrentImageContext(); uploadView.dataToUpload = UIImagePNGRepresentation(imageRotated); 但它返回给我空白图像......

标签: ios objective-c xcode ipad uiimage


【解决方案1】:

看看这个:http://www.catamount.com/blog/1015/uiimage-extensions-for-cutting-scaling-and-rotating-uiimages/

只要打电话

UIImage *rotatedImage = [originalImage imageRotatedByDegrees:180.0];

Source

【讨论】:

  • 伙计,这简直太棒了,效果很好!感谢您的链接。
【解决方案2】:

UploadView.DataToUpload = [UIImage imageWithCGImage:[image CGImage] scale:1.0orientation : UIImageOrientationDown];

用于 180 度旋转。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 2012-12-30
    • 2011-10-24
    • 2011-05-14
    • 2018-03-19
    • 2023-04-06
    相关资源
    最近更新 更多