2013-01-11 4 views
0

앨범 테이블의 사진이있는 데이터베이스가 있습니다. 모든 이미지를 배열로 가져와 테이블에 표시합니다. 90도 회전하는 이미지가 거의 없습니다.iphone 테이블의 일부 이미지가 자동으로 회전합니다.

여기에 cellForRow 메소드가 있습니다.

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

이미지가 거의 나오지 않지만 이미지가 거의 회전하지 않습니다.

도와주세요.

미리 감사드립니다.

답변

0

UIImage에는 "imageOrientation"이라는 assign 속성이 있습니다. 그래서이 방법이 도움이 될 수 있습니다 당신

  • (있는 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; 
    

    }

+1

내가 모든 이미지에 대한 이미지 방향을 얻고 있지만, 어떤 이미지가 회전 중입니다. 시도해 보았습니다. (temp.albumPictureClass == UIImageOrientationUP) {NSLog (@ "Up");} 모든 이미지가이 메시지를 인쇄했습니다. – Durgaprasad

+0

즉, 이미지 방향이 모두 "위로"있음을 의미합니다.이미지가 90도 회전하고 코드로 회전합니다. 영어가 매우 안좋아서 제가 말한 것을 이해할 수 있는지 확신 할 수 없습니다. --!죄송합니다! – iuser1969782

+0

예. 알겠습니다. 나는 당신의 방법을 받아 들였습니다. 그것은 완벽. 고맙습니다. – Durgaprasad

0

다음 샘플을 참조하십시오. 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 
을 다음과 같은 몇 가지 방향을 가지고 주장(210)

는 SO 다운로드이 샘플 데모를 통해 이동하시기 바랍니다

MyImagePicker Demo

참고 : 당신은 당신이

NSUInteger groupTypes = ALAssetsGroupAlbum | ALAssetsGroupEvent | ALAssetsGroupFaces|ALAssetsGroupLibrary|ALAssetsGroupSavedPhotos|ALAssetsGroupPhotoStream; 
을 다음과 같은 RootViewController.m 코드를 변경해야하는 모든 앨범에서 표시하려는 경우
관련 문제