views:

75

answers:

2

Hello,
in my class I have an attribute IBOutlet UIImageView *imageView; And if I want to draw an image in this view I do : imageView.image = [UIImage imageNamed:@"foo.png"];
But how can I do to draw some points with coordinate x, y (in pixel) directly in the view ?

Thanks !

+1  A: 

UIImageView isn't designed to allow arbitrary drawing code. For this purpose, use a UIView and override the drawRect: method.

Marcelo Cantos
A: 

After you follow Marcelo's suggestion to draw in the view, you can pull the uiimage from the view with something like:

+(UIImage *)grabImageFromView: (UIView *) viewToGrab {

UIGraphicsBeginImageContext(viewToGrab.bounds.size);

[[viewToGrab layer] renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;

}

Oldmicah