Выпуск вращающегося UIImage - PullRequest
0 голосов
/ 07 октября 2010

Мой код ниже.Кто-нибудь знает, что происходит?

Извините за неполную информацию.Изображение просто исчезает!

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

    UIImage *imCaptured = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
    CGImageRef cgirCropped = CGImageCreateWithImageInRect(imCaptured.CGImage, CGRectMake(700.0f, 430.0f, 650.0f, 650.0f));
    UIImage *imCropped = [UIImage imageWithCGImage:cgirCropped];

    UIGraphicsBeginImageContext(imCropped.size);
    CGContextRef cgcrRotation = UIGraphicsGetCurrentContext();

    switch (imCaptured.imageOrientation) {
        case UIImageOrientationUp:
            CGContextRotateCTM(cgcrRotation, (180 * M_PI / 180));
            break;
        case UIImageOrientationDown:

            break;
        case UIImageOrientationLeft:

            break;
        case UIImageOrientationRight:
            CGContextRotateCTM(cgcrRotation, (90 * M_PI / 180));
            break;
    }
    [imCropped drawAtPoint:CGPointMake(0.0f, 0.0f)];
    [imvPreview setImage:UIGraphicsGetImageFromCurrentImageContext()];
}

1 Ответ

3 голосов
/ 07 октября 2010

Я не проверял код, но я думаю, что он вращается вокруг источника, поэтому вам также нужно перевести что-то вроде:

...
case UIImageOrientationUp:
        CGContextRotateCTM(cgcrRotation, (180 * M_PI / 180));
        CGContextTranslateCTM(ctxt, -imCropped.size.width, -imCropped.size.height);
        break;
...
...