1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Turn Pixels On

Discussion in 'iPhone/iPad Programming' started by xcodeNewbie, Jul 19, 2011.

  1. macrumors member

    I'm trying to make an app in which the user enter an equation (i.e y=2x) and the iPhone will graph it on screen. I am wondering how to turn on individual pixels on the iPhone screen so I can draw the graph. At first I tried creating a whole bunch of rectangles with height and width of 1, but the program ran way too slowly trying to allocate and initialize all those rectangles. So I'm wondering if there's a simple command for turning on pixels, something like:
    turnPixelOn:(UIView *)aView atCoordinates:(CGPoint)aPoint withColor:(UIColor*)aColor.
  2. Moderator


    Staff Member

    You cannot "turn a pixel on". You can easily create a bitmap image, get the raw data array that represents that image and with a bit of knowledge about the structure of the image (you can get this with low level CoreGraphics functions) you can manipulate the pixels directly.

    Note this is a reasonably complex thing to do and I'm certainly not about to post code.
  3. macrumors member

    Drawing Pixels

    OK, thanks. I read about the bitmapping and I was just trying to find an easier way to graph an equation. But if this is what it takes....
  4. Moderator


    Staff Member

    You could try adding a UIWebView and using a Google Chart.
  5. macrumors regular

    You can subclass UIView and implement your own drawRect method to make your graph or you can draw directly into a bitmap and present that bitmap as a view.

    Either way you need to use CoreGraphics to perform the actual drawing. Check out the WWDC 2011 videos, session 129 "Practical Drawing for iOS Developers" shows how to draw a graph.
  6. macrumors regular

    The first thing that I would try for graphing is drawing lines with a CGPathRef. I think that would be pretty fast and easy to do, probably less code than you have now with the 1x1 rectangles.

Share This Page