0

I have a UIImageView within an UIViewController and want to add a simple image on the existing imageView.

The viewDidLoad-method looks like this:

    UIImage *test;
    test = [UIImage imageNamed:@"position-dot.png"];

    [test drawAtPoint:CGPointMake(100,100) ];

A part of the error-message I receive look like this:

CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context  and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

CGContextSetBlendMode: invalid context 0x0. This is a serious error.

I tested to reset my iOS Simulator (solution in other threads about this), but that didn't fix the problem.

Irfan
  • 4,301
  • 6
  • 29
  • 46
iHank
  • 526
  • 9
  • 22

1 Answers1

1

While the approach in my above comment does silence the warning, I was finding that the image was not displaying as I expected. I found that the easiest way to make drawAtPoint work was to subclass UIView and put the exact code that you have into the implementation of drawRect: like so.

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    UIImage *test;
    test = [UIImage imageNamed:@"position-dot"];
    [test drawAtPoint:CGPointMake(100.0, 100.0)];
}

Then, in your controller:

MyViewSubclass *view = [[MyViewSubclass alloc] initWithFrame:self.view.frame];
[self.view addSubview:view];
geraldWilliam
  • 4,123
  • 1
  • 23
  • 35
  • Thanks, that did show the image. But the image that it is supposed to be on top is now black. It is black even if I add it as a sub view to the ImageView (the imageview that now is black). Why is that? – iHank Apr 02 '14 at 17:54
  • Oh right. Essentially, both images need to be drawn into the same view. See this forum answer [http://iphonedevsdk.com/forum/iphone-sdk-development/113055-saving-overlay-and-ui-captured-image-to-single-photo.html] from @DuncanC for an example of how to implement a "watermarked" image. – geraldWilliam Apr 02 '14 at 18:05