Changing Pixel Values using CG
From my research it appears that there is no sample code that I can find that illustrates how to modify one or more pixels for the current view (I want to change pixels and not draw 1pt rects or something cheesy like that). I want to use CoreGraphics and not OpenGL.
My understanding is that what I need to do is keep around an bitmap, change the pixels in that, and then use that to create a CGImage that gets drawn to the context.
What I am trying to find is some code that actually shows this working. In other words:
1) Creating the offscreen bitmap.
2) Changing 1 pixel to red or whatever.
3) Updating the current view with the new bitmap
Does anyone have any pointers on where to find an example that does this?
My understanding is that what I need to do is keep around an bitmap, change the pixels in that, and then use that to create a CGImage that gets drawn to the context.
What I am trying to find is some code that actually shows this working. In other words:
1) Creating the offscreen bitmap.
2) Changing 1 pixel to red or whatever.
3) Updating the current view with the new bitmap
Does anyone have any pointers on where to find an example that does this?
1) You create a CGBitmapContext
2) You'd modify the memory of the context
3) You'd create a CGImage for the context, and
4) You'd draw that CGImage into the current view context.
This page pretty much covers it:
http://developer.apple.com/library/mac/#...3-CJBHBFFE
The only question is where you get your view context from to use in CGContextDrawImage.
If you're drawing into a Cocoa NSView, you would get the current view context by:
If you're drawing into a UIView, you'd use UIGraphicsGetCurrentContext.
2) You'd modify the memory of the context
3) You'd create a CGImage for the context, and
4) You'd draw that CGImage into the current view context.
This page pretty much covers it:
http://developer.apple.com/library/mac/#...3-CJBHBFFE
The only question is where you get your view context from to use in CGContextDrawImage.
If you're drawing into a Cocoa NSView, you would get the current view context by:
Code:
(CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]If you're drawing into a UIView, you'd use UIGraphicsGetCurrentContext.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| passing values from vertex to fragment shader | Sumaleth | 6 | 8,631 |
Feb 18, 2011 01:54 AM Last Post: Holmes |
|
| [CoreGraphics] Image manipulation - pixel by pixel | g00se | 5 | 7,082 |
Jul 28, 2010 08:27 AM Last Post: ThemsAllTook |
|
| Reading texture colors values | Leroy | 6 | 4,113 |
Jul 24, 2007 10:06 PM Last Post: Leroy |
|
| Effifcient State Changing | Nick | 7 | 3,047 |
Apr 6, 2006 06:33 AM Last Post: TomorrowPlusX |
|
| Changing the Mask in OpenGL | kodex | 2 | 3,399 |
Jan 18, 2006 09:21 PM Last Post: kodex |
|

