Changing Pixel Values using CG

Posts: 1
Joined: 2010.11
Post: #1
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?
Quote this message in a reply
⌘-R in Chief
Posts: 1,277
Joined: 2002.05
Post: #2
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:
(CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]

If you're drawing into a UIView, you'd use UIGraphicsGetCurrentContext.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  passing values from vertex to fragment shader Sumaleth 5 17,222 Feb 18, 2011 01:54 AM
Last Post: Holmes
  [CoreGraphics] Image manipulation - pixel by pixel g00se 5 19,206 Jul 28, 2010 08:27 AM
Last Post: ThemsAllTook
  Reading texture colors values Leroy 6 7,154 Jul 24, 2007 10:06 PM
Last Post: Leroy
  3D animation/morphing/texture changing wyrmmage 7 6,871 Dec 31, 2006 10:30 AM
Last Post: Leisure Suit Lurie
  Effifcient State Changing Nick 7 6,817 Apr 6, 2006 06:33 AM
Last Post: TomorrowPlusX