我正在使用相機選取器控制器拍攝圖片,並將其顯示在我的應用程序中。但是我沒有使用UIImageView
來顯示圖片。我在UIView
上繪製了UIImage
,我得到的結果是顛倒的圖像。下面是截圖:UIImage在UIView上繪製時反轉
後,我點擊使用照片結果:
這裏是我的代碼:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
dView=[[drawView alloc]initWithFrame:imageUIView.frame];
[dView drawImage:chosenImage];
[imageUIView addSubview:dView];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
和DVIEW:
-(void)drawImage:(UIImage *) imageToDraw{
self.pic=imageToDraw;
[imageToDraw drawInRect:self.frame];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect targetBounds = self.layer.bounds;
// fit the image, preserving its aspect ratio, into our target bounds
CGRect imageRect = AVMakeRectWithAspectRatioInsideRect(self.pic.size,
targetBounds);
// draw the image
CGContextDrawImage(context, imageRect, self.pic.CGImage);
// Save the screen to restore next time around
imageRef = CGBitmapContextCreateImage(context);
}
我試過CGAffineTransformMakeRotation
和CGContextRotateCTM
以正確顯示圖像,但它們旋轉圖像,而不是按正確的順序顯示內容。正如你所看到的,圖像中的內容完全顛倒了。
如何繪製uiimage
而不作任何更改?
@picciano爲什麼?這沒有關係。 – rmaddy