从核心数据加载的iPhone UIImage逆时针旋转90度,可以通过以下方法实现:
- (UIImage *)rotateImage:(UIImage *)image {
CGImageRef imageRef = image.CGImage;
CGFloat width = CGImageGetWidth(imageRef);
CGFloat height = CGImageGetHeight(imageRef);
CGContextRef bitmap = CGBitmapContextCreate(nil, width, height,
CGImageGetBitsPerComponent(imageRef),
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
CGImageGetBitmapInfo(imageRef));
CGContextRotateCTM(bitmap, M_PI_2);
CGContextDrawImage(bitmap, CGRectMake(0, 0, height, width), imageRef);
CGImageRef rotatedImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *rotatedImage = [UIImage imageWithCGImage:rotatedImageRef];
CGContextRelease(bitmap);
CGImageRelease(rotatedImageRef);
return rotatedImage;
}
- (UIImage *)rotateImage:(UIImage *)image {
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextRotateCTM(context, M_PI_2);
[image drawAtPoint:CGPointMake(0, -image.size.width)];
UIImage *rotatedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return rotatedImage;
}
这两种方法都可以实现从核心数据加载的iPhone UIImage逆时针旋转90度的效果。
领取专属 10元无门槛券
手把手带您无忧上云