2012-03-12 7 views
0

У меня проблема Когда я получаю изображение с iPhone-камеры. я могу получить это во всех направлениях, таких как LeftLandscape, RightLandscape, Portrait и portrait вверх ногами.Вращение UIImage в iPhone

Теперь, как я могу повернуть изображение сгружен из делегатов камеры только в одной ориентации т.е. только в портретном или ландшафтном справа

Может кто-нибудь помочь?

ответ

1

Попробуйте это ...

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; 

Также смотрите эту ссылку ... это поможет Вам ...

http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/

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; 
} 
Смежные вопросы