我遇到問題 當我從iPhone相機獲取圖像時。我可以像所有的方向,像左邊的風景,右邊的風景,肖像和肖像倒過來。在iPhone中旋轉UIImage
現在,我怎麼將圖像從相機中取出代表旋轉到只有一個方向,即只有在縱向或橫向右
任何人可以幫助?
我遇到問題 當我從iPhone相機獲取圖像時。我可以像所有的方向,像左邊的風景,右邊的風景,肖像和肖像倒過來。在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;
也可參考此鏈接...這將幫助你......
http://www.platinumball.net/blog/2009/03/30/iphone-uiimage-rotation-and-mirroring/
NYXImagesKit: Handy UIImage Categories
本傑明·戈達爾
這是在UIImage f或以一種高效且易於使用的方式旋轉,調整大小,過濾,增強等等。可能會在你的一些應用程序中有用!
嘗試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;
}