2011-10-07 3 views
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]; 
} 

답변

2

당신은 값으로 힌트> = 1

+0

감사 UIBezierPathlineWidth 속성을 설정해야하지만, 그 중 하나가 도움이되지 않습니다. UIGraphicsGetCurrentContext 및 UIGraphicsPushContext를 사용해야한다는 것을 알았습니다. 왜냐하면 UIView에서 그리지는 않았지만 도움이되지 않았기 때문입니다. – Arne

+0

그럼 비트 맵 안에서 드로잉을 위해 생성 한 그래픽 콘텍스트 안에서 드로잉을하고 있습니다. CoreGraphics로 직접 드로잉을 할 수 있습니까? (CGPath 사용) –

+3

좋아, 나는 꽤 바보 같았다. 나의 UIImageView는 Aspect Fill로 설정되었다. 그래서 좌표는 뷰 밖에 있습니다 ... 이제 Aspect Fit으로 설정했습니다. 이것은 내가 원했던 것과 더 비슷합니다. 이제는 직사각형을 봅니다. :) – Arne

관련 문제