Simple Drawing Program

Discussion in 'iOS Programming' started by HarryWorksInc, May 8, 2010.

  1. HarryWorksInc macrumors regular

    Joined:
    Feb 21, 2010
    #1
    I am just creating a simple drawing program, I have been a developer for years now and I know I must be doing something insanely stupid but heres my code,
    HTML:
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    	CGPoint thumbPoint;
    	UITouch *thumb = [[event allTouches] anyObject];
    	thumbPoint = [thumb locationInView:thumb.view];
    	
    	UIImageView *newImage = [[UIImageView alloc] initWithFrame:CGRectMake(thumbPoint.x, thumbPoint.y, 17, 17)];
    	newImage.image = [UIImage imageNamed:@"BlackDot.png"];
    }
    I don't know what i'm doing wrong but all this is supposed to do is create a small square on the screen this repeats in the touchesMoved void.

    Nothing happens though, help would be much obliged.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    1) That is a totally insane way to draw a single pixel.

    2) You've not added the new view a subview of any visible view so it's not actually on screen anywhere.
     
  3. HarryWorksInc thread starter macrumors regular

    Joined:
    Feb 21, 2010
    #3
    thanks, that worked but how would you do it, if my way is so insane?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    The reason your way is insane is that you'll end up with so many views that performance will be poor. And there will probably be quite a lot of lag too.

    Option 1:

    Composite yourself: just create a UIImage and composite your "pixel" image yourself. Downside of this is tracking your pixels and the more you have the longer this will take

    Option 2:

    Well then re-lock focus on the composited image from last time and composite the new pixel in. This will probably work OK

    Option 3:

    Do it the "right" way. Create a CGBitmapContext with the correct options and "draw" by simply manipulating the image bytes directly.
     

Share This Page