On Wed, Oct 22, 2008 at 10:25 AM, Development <[EMAIL PROTECTED]>wrote:
> Good day! > > I am working on pixel based drawing tool, and could use some hint on how to > handle selection areas. > > In the program, each document has a couple different Bitmap context (24 bit > RGP space CGBitmapContext ) at the same time. I draw into a scroll view > using a Layer (CGLayer). Whenever one of the bitmap context changes, I copy > the changes into the layer, but scrolling within the view is done only with > the layer except for drawing the selection area. > > As always, I want to make sure there isn't a better way of doing what I am > doing now. > > To handle the selection, I have been using a CGBitmapContext (created with > method CGBitmapContextCreate with a bitsPerComponent of 8, a color space of > GreySpace, and CGBitmap info of kCGImageAlphaNone). This gives me an > editable context, so that I can create the selection graphic using Quartz > draw rectangles and ovals. When I need to draw using the selection, I > convert the selection into an image (CGBitmapContextCreateImage), clip the > context to that image (CGContextClipToMask) and then do whatever drawing I > want to do (ex. invert, special fill, you name it). > > First of all, it is possible to create a single bit bitmap context (only > black and white)? I could only get 8 bit greyscale working correctly. Nope. The supported formats for contexts are listed at < http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/chapter_3_section_4.html#//apple_ref/doc/uid/TP30001066-CH203-BCIBHHBB >. > Should I be using ImageMask for these operations? I did not create a bitmap > mask (using CGImageMaskCreate) because I needed to be able to constantly > modify the mask using rectangle and oval commands (and I could not get that > call to work). Your current approach to drawing and using the selection sounds okay to me. I may not be following precisely. An alternative might be to keep a vector-based internal representation of the selection, with paths. This might be beneficial if the user can, say, scale the document without losing the selection. > Lastly, when when drawing between bitmap context (basically copying one > section to another), is the best way to create an Image from the bitmap info > (CGBitmapContextCreateImage) and then draw using the image. Apple > documentation suggest that this is quick enough. If I create an image, and > then modify the context, the image I created would have a copy of the data, > not any changes. Yes, that's a good way to copy image data from a bitmap context to another destination. I didn't really follow the description of where and how CGLayers and CGBitmapContexts are used. If you're satisfied that that part is good, though, the rest sounds fine to me. :-) Of course, if you see performance issues, the profiling tools may help point to the problems. -Ken Cocoa Frameworks _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]