0

アルバムテーブルに写真を含むデータベースがあります。すべての画像を配列で取得し、表に表示します。問題は、ほとんどの画像が 90 度回転していることです。

これがcellForRowメソッドの内容です。

AlbumInformation * temp=[albumInfoArray objectAtIndex:indexPath.row];
cell.albumPicImageView.image=temp.albumPictureClass;
return cell;

すべての画像を取得しますが、回転はほとんどありません。

助けてください。

前もって感謝します

4

2 に答える 2

0

UIImageには、割り当てプロパティ「imageOrientation」があります。したがって、この方法はあなたを助けるかもしれません

  • (UIImage *)fixOrientation:(UIImage *)aImage {

    // No-op if the orientation is already correct  
    if (aImage.imageOrientation == UIImageOrientationUp)   
        return aImage;  
    
    // We need to calculate the proper transformation to make the image upright.  
    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.  
    CGAffineTransform transform = CGAffineTransformIdentity;  
    
    switch (aImage.imageOrientation) {  
        case UIImageOrientationDown:  
        case UIImageOrientationDownMirrored:  
            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);  
            transform = CGAffineTransformRotate(transform, M_PI);  
            break;  
    
        case UIImageOrientationLeft:  
        case UIImageOrientationLeftMirrored:  
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);  
            transform = CGAffineTransformRotate(transform, M_PI_2);  
            break;  
    
        case UIImageOrientationRight:  
        case UIImageOrientationRightMirrored:  
            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);  
            transform = CGAffineTransformRotate(transform, -M_PI_2);  
            break;  
        default:  
            break;  
    }  
    
    switch (aImage.imageOrientation) {  
        case UIImageOrientationUpMirrored:  
        case UIImageOrientationDownMirrored:  
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);  
            transform = CGAffineTransformScale(transform, -1, 1);  
            break;  
    
        case UIImageOrientationLeftMirrored:  
        case UIImageOrientationRightMirrored:  
            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);  
            transform = CGAffineTransformScale(transform, -1, 1);  
            break;  
        default:  
            break;  
    }  
    
    // Now we draw the underlying CGImage into a new context, applying the transform  
    // calculated above.  
    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,  
                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,  
                                             CGImageGetColorSpace(aImage.CGImage),  
                                             CGImageGetBitmapInfo(aImage.CGImage));  
    CGContextConcatCTM(ctx, transform);  
    switch (aImage.imageOrientation) {  
        case UIImageOrientationLeft:  
        case UIImageOrientationLeftMirrored:  
        case UIImageOrientationRight:  
        case UIImageOrientationRightMirrored:  
            // Grr...  
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);  
            break;  
    
        default:  
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);  
            break;  
    }  
    
    // And now we just create a new UIImage from the drawing context  
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);  
    UIImage *img = [UIImage imageWithCGImage:cgimg];  
    CGContextRelease(ctx);  
    CGImageRelease(cgimg);  
    return img;  
    

    }

于 2013-01-11T11:41:51.010 に答える
0

以下のサンプルを参照してください。次の 2 つのケースの PhotoDisplayViewController.m テストでは、誰にも説明する必要なく、自動的に回答が得られます。

ケース 1: UIImageOrientation を使用

ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];

    UIImage *fullScreenImage = [UIImage imageWithCGImage:[assetRepresentation fullScreenImage] scale:[assetRepresentation scale] orientation:(UIImageOrientation)[assetRepresentation orientation]];

ケース 2: UIImageOrientation なし

ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation];

    UIImage *fullScreenImage = [UIImage imageWithCGImage:[assetRepresentation fullScreenImage] scale:[assetRepresentation scale] orientation:nil];

アサーションから読んでいるとき、次のようないくつかの方向性があります

 UIImageOrientationUp,            // default orientation
    UIImageOrientationDown,          // 180 deg rotation
    UIImageOrientationLeft,          // 90 deg CCW
    UIImageOrientationRight,         // 90 deg CW
    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip
    UIImageOrientationDownMirrored,  // horizontal flip
    UIImageOrientationLeftMirrored,  // vertical flip
    UIImageOrientationRightMirrored, // vertical flip

このサンプルデモをダウンロードしてください

MyImagePicker デモ

注: すべてのアルバムから表示する場合は、RootViewController.m のコードを次のように変更する必要があります。

NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces|ALAssetsGroupLibrary|ALAssetsGroupSavedPhotos|ALAssetsGroupPhotoStream;
于 2013-01-11T11:39:24.863 に答える