views:

496

answers:

3

Hi guys;

I am trying to draw individual pixels in xcode to be outputted to the iphone. I do not know any OpenGL or Quartz coding but I do know a bit about Core Graphics. I was thinking about drawing small rectangles with width and height of one, but do not know how to implement this into code and how to get this to show in the view. Any help is greatly appreciated.

Thanks, Brett

A: 

That would work. There are some reference materials here http://maniacdev.com/2009/09/6-resources-for-learning-core-graphics/ although just about any sample will show how to draw a line/circle/image/point which should get you going.

Andiih
A: 

I still can't get this to work after looking at those examples. I want to be able to send x and y points to my UIView subclass called "View" which will update the screen and display the pixel. Then I want to send more points and continually update to display all the points.

This is my current code:

//View_Controller.h
#import <UIKit/UIKit.h>

@class View;
@interface Mandelbrot_SetViewController : UIViewController {

    View *otherView;

}

@property(nonatomic, retain)View *otherView;

@end


//View_Controller.m
#import "Mandelbrot_SetViewController.h"
#import "ComplexNumber.h"
#import "View.h"


@implementation Mandelbrot_SetViewController
@synthesize otherView;

@class View;
...
...

- (void)viewDidLoad {

    [otherView setXY:100 andY:100];

    [super viewDidLoad];
}
...
@end


//View.h
#import <UIKit/UIKit.h>


@interface View : UIView {


}

- (void)setXY:(double)ax andY:(double)ay;

@end


//View.m
#import "View.h"


@implementation View


- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Initialization code
    }
    return self;
}

- (void)setX:(double)ax andY:(double)ay{

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0); // black colour
    CGContextFillRect(context, CGRectMake(ax, ay, 1.0, 1.0)); // draw pixel
    [self setNeedsDisplay];


}

/* 
- (void)drawRect:(CGRect)rect;
{  
}
*/

- (void)dealloc {
    [super dealloc];
}


@end

The screen will not show the pixels. Any help is greatly appreciated :)

Brett
A: 

All drawing needs to go into the - (void)drawRect:(CGRect)rect method. [self setNeedsDisplay] flags the code for a redraw. problem is your redrawing nothing.

Gordon