畫圖片

`- (void)rotateTapped:(id)sender {
UIImage *currentImage = _imageView.image;
CGImageRef currentCGImage = currentImage.CGImage;

CGSize originalSize = currentImage.size;
CGSize rotatedSize = CGSizeMake(originalSize.height, originalSize.width);

CGContextRef context = CGBitmapContextCreate(NULL,
                                             rotatedSize.width,
                                             rotatedSize.height,
                                             CGImageGetBitsPerComponent(currentCGImage),
                                             CGImageGetBitsPerPixel(currentCGImage) * rotatedSize.width,
                                             CGImageGetColorSpace(currentCGImage),
                                             CGImageGetBitmapInfo(currentCGImage));

CGContextTranslateCTM(context, rotatedSize.width, 0.0f);
CGContextRotateCTM(context, M_PI_2);
CGContextDrawImage(context, (CGRect){.origin=CGPointZero, .size=originalSize}, currentCGImage);

CGImageRef newCGImage = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newCGImage];

self.imageView.image = newImage;

}
`

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章