2012-03-12 86 views
0

我遇到问题 当我从iPhone相机获取图像时。我可以像所有的方向,像左边的风景,右边的风景,肖像和肖像倒过来。在iPhone中旋转UIImage

现在,我怎么将图像从相机中取出代表旋转到只有一个方向,即只有在纵向或横向右

任何人可以帮助?

回答

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; 
}