drawing into an existing CGImage

Ok, maybe I'm hung up on Mac OS X design patterns, just tell me if that's the case.


the problem:

I need to draw a line on an existing CGImage.

There's no LockFocus methods for CGImage, There's no obvious documented way to get the already created Context of a Bitmap in the CGImage. There's no obvious or explicit code explaining the procedure.


I have the reference to the image, I have the two points that make up the line, I know all of the code to draw that line... I just cannot make the context associated to that image, the current context. What gives? what is the design pattern? Please tell me where I can read about this.

I refuse to believe that while I am drawing (following the Touch) I need to copy the ENTIRE image into a new image.

That is rediculous, yet, that's what all of the examplers show: copy the image into a new context, and then do your drawing before you end the context, and capture it in the image.

Refuse to believe it if you like, but it's the truth. CGImages are explicitly immutable.


You could create a bitmap context, draw the image into it, then draw the line, and create a new image from that.


Alternatively, it sounds like your use case is better suited to just using the bitmap context as your main object. Keep it around and draw into it whenever you want to "change the image". Just at the point where you want a CGImage to store to file, transmit over a network, or draw elsewhere, create a CGImage from the bitmap context, use it, and release it.

Hi Ken.

I was able to implement a draw loop that creates a new CGImage for each call to touchesMoved(), that largely does what i would like.


There are some problems, which are frankly: mistifying. the worst one being:

my touches are mirrored across the Y axis.

I take the raw touches set and stamp each one of them. This results in vertical mirroring of the line. I don't even know where to start looking for help fixing that. I feel stupid asking if it's expected behavior, there's no way this should be expected behavior. And like I said: I'm not changing the list of touches in any way.


but back to use case, because I think this is causing a rats nest of other (I won't call them minor, but I suspect that they are related) issues. There's another consideration for the use case: I'm feeding the image into the content property of a CALayer. It makes for very good zoom/pan/rotate manipulation.

it is my understanding that CALayer requires a CGImage (in the boundaries of our discussion) So while I'd love to keep the context around, in order to display it, I still need to make the CGimage, and apply it... during each call to the touchesMoved function. Currently I am copying the current image into a new Context, but I did try to maintain a Context, and CALayer did not like that. I'm in bootstrap mode, as I try to make sense out of IOS' design patterns. So I'm making prototypes as quickly as I can.

drawing into an existing CGImage
 
 
Q