Johna
Johna

Reputation: 13

Drawing pixels with XCode

I am trying to draw individual pixels in xcode. I already know Objective-C but not the Quartz/graphics stuffs and I'nm not interested at the moment. I simply want a basic app that let me have a map of X*Y and being able to show pixel at (x,y) with color rgb.

I don't know how to find a tutorial for this, and I think it must be very quick. Do you guys have a file like this, or could point me to a tutorial? Any help is greatly appreciated.

Upvotes: 1

Views: 1898

Answers (3)

Anne
Anne

Reputation: 27073

Simply use NSBitmapImageRep with setColor:atX:y:

Create a empty NSBitmapImageRep.

Every time you need to update the view do something like this:
- Set the specific pixel to a certain color with setColor:atX:y:
- Convert NSBitmapImageRep to NSImage
- Show result in a NSImageView

This works perfect if you don't need to update the view too many times/sec.

Upvotes: 3

hotpaw2
hotpaw2

Reputation: 70733

You could either use CoreGraphic to draw a filled rect in a drawRect after a setNeedsDisplay on the view. Or you could generate a bitmap context and assign it to the layer contents of your view at a 1.0 scale if you want actual pixels instead of 1x1 point rectangles.

Upvotes: 0

lxt
lxt

Reputation: 31304

I already know Objective-C but not the Quartz/graphics stuffs and I'nm not interested at the moment. I simply want a basic app that let me have a map of X*Y and being able to show pixel at (x,y) with color rgb.

If you're not interested in learning Core Graphics, then tough luck. You get two choices for graphics: OpenGL, or UIKit/Core Graphics. Your choice, but Core Graphics is considerably easier. You can use OpenGL to paint on a per pixel basis, but I'm assuming if you have no interest in learning Core Graphics you're probably not going to be keen on OpenGL. For high performance applications you're looking at OpenGL as the only realistic option.

So, if you don't want to learn OpenGL your best bet is the Quartz programming guide:

http://developer.apple.com/library/ios/#DOCUMENTATION/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html%23//apple_ref/doc/uid/TP40007533-SW1

Out of interest, why wouldn't you want to look into Quartz?

Upvotes: 1

Related Questions