1
我試圖用一些額外的信息疊加圖像:一些文本和矩形。現在我被困在畫矩形。他們只是不會出現。我究竟做錯了什麼?圖像本身正在繪製,所以圖形上下文必須正常。在UIGraphics上下文中繪製矩形不起作用
- (void)drawTag:(NSString *)tag withRect:(CGRect)rect
{
// Set the color in the current graphics context for future draw operations
[[UIColor yellowColor] setStroke];
[[UIColor yellowColor] setFill];
// Create our drawing path
UIBezierPath* drawingPath = [UIBezierPath bezierPathWithRect:rect];
// actually draw it
[drawingPath stroke];
}
- (IBAction)showDetails:(id)sender
{
// draw the image
UIGraphicsBeginImageContext(self.userImage.size);
// This one shows up:
[self.userImage drawAtPoint:CGPointZero];
// This one does not:
[self drawTag:@"Test" withRect:CGRectMake(10, 10, 50, 50)];
// Show the whole thing:
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:self.imageViewController animated:YES];
}
謝謝你的提示,但這並沒有幫助。我也只是讀了我應該使用UIGraphicsGetCurrentContext和UIGraphicsPushContext,因爲我沒有繪製UIView,但這也沒有幫助。 – Arne
那麼你正在繪製一個圖形上下文內創建繪製位圖..繪圖CoreGraphics直接工作? (使用CGPath) –
好吧,我很愚蠢:我的UIImageView被設置爲Aspect Fill。所以座標位於視圖之外......我現在將其設置爲Aspect Fit,這更像我想要的,現在我看到了我的矩形。 :) – Arne