2012-03-12 3 views
0

문제가 있습니다 iPhone 카메라에서 이미지를 가져올 때. 나는 모든 방향에서 그것을 얻을 수 있습니다. LeftLandscape, RightLandscape, Portrait, portrait와 같은 거꾸로. iPhone에서 UIImage 회전

지금 내가 어떻게 만 세로 또는 가로 오른쪽

수 누군가 도움말에서 한 방향으로 만, 즉에 카메라 대표단에서 가져온 이미지를 회전 할 수 있습니까? 또한

CGSize size = sizeOfImage; 
UIGraphicsBeginImageContext(size); 
CGContextRef ctx = UIGraphicsGetCurrentContext(); 
CGContextRotateCTM(ctx, angleInRadians); 
CGContextDrawImage(UIGraphicsGetCurrentContext(), 
    CGRectMake(0,0,size.width, size.height), 
    image); 

UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return image; 

이 링크를 참조

... 그것은 당신을 도울 것입니다

답변

0

NYXImagesKit: Handy UIImage Categories

벤자민으로 고다르

이것은 UIImage f의 카테고리 중 편리한 세트입니다. 효율적이고 사용하기 쉬운 방식으로 회전, 크기 조정, 필터링, 향상 등의 작업을 수행 할 수 있습니다. 일부 앱에서 유용 할 수 있습니다.

0

는 this.It 도움이 될 것입니다보십시오

-(UIImage *)resizeImage:(UIImage *)image { 

CGImageRef imageRef = [image CGImage]; 
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef); 
CGColorSpaceRef colorSpaceInfo = CGColorSpaceCreateDeviceRGB(); 

if (alphaInfo == kCGImageAlphaNone) 
    alphaInfo = kCGImageAlphaNoneSkipLast; 

int width, height; 

width = 640;//[image size].width; 
height = 640;//[image size].height; 

CGContextRef bitmap; 

if (image.imageOrientation == UIImageOrientationUp | image.imageOrientation == UIImageOrientationDown) { 
    bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo); 

} else { 
    bitmap = CGBitmapContextCreate(NULL, height, width, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo); 

} 

if (image.imageOrientation == UIImageOrientationLeft) { 
    NSLog(@"image orientation left"); 
    CGContextRotateCTM (bitmap, radians(90)); 
    CGContextTranslateCTM (bitmap, 0, -height); 

} else if (image.imageOrientation == UIImageOrientationRight) { 
    NSLog(@"image orientation right"); 
    CGContextRotateCTM (bitmap, radians(-90)); 
    CGContextTranslateCTM (bitmap, -width, 0); 

} else if (image.imageOrientation == UIImageOrientationUp) { 
    NSLog(@"image orientation up"); 

} else if (image.imageOrientation == UIImageOrientationDown) { 
    NSLog(@"image orientation down"); 
    CGContextTranslateCTM (bitmap, width,height); 
    CGContextRotateCTM (bitmap, radians(-180.)); 

} 

CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef); 
CGImageRef ref = CGBitmapContextCreateImage(bitmap); 
UIImage *result = [UIImage imageWithCGImage:ref]; 

CGContextRelease(bitmap); 
CGImageRelease(ref); 

return result; 
} 
관련 문제