Changing Pixel Values using CG - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Changing Pixel Values using CG (/thread-8348.html)
Changing Pixel Values using CG - LIPH700 - Nov 25, 2010 01:24 PM
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?
RE: Changing Pixel Values using CG - SethWillits - Nov 25, 2010 03:17 PM
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:
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.