Quantcast

Forums | MacLife

You are not logged in.

#1 2007-11-14 9:45 pm

iZach004
Member
From: Indianapolis, IN, 46240
Registered: 2001-06-04
Posts: 176
Website

NSImage, QCView, and Cocoa

I'm typically a lower-level kinda of guy, but am diving head-first into Cocoa.

I love it. But there are a few things that get to me.

I've been playing around for a few days in Quartz Composer in Cocoa projects, which is probably the coolest thing I've ever seen, but I'm a little confused on how certain types of data are stored and if I can manipulate it directly.

I'd like to extract the contents of a QCView window to an NSImage. I'm under the impression that there's snapshotImage, but it's not like a method or anything, I'm unsure how to use it.

Also, does anyone know how data is stored in an NSImage? Can I change things directly, because it clearly doesn't just work like an array ;-) I mean, if I want to read the value of a pixel and set the value of another pixel, is there a method for doing this?

Last edited by iZach004 (2007-11-14 9:47 pm)

Offline

 

#2 2007-11-15 11:06 am

Metacell
misanthropist
From: The space between the spaces
Registered: 2005-03-19
Posts: 5863
Website

Re: NSImage, QCView, and Cocoa

NSImage is one the heftier Application Kit classes.  It's main duty is compositing data from many possible sources and translating this into data that can be displayed on all kinds of viewing devices, including printing.  It can even delegate to another class how the image should be drawn.  It isn't really meant for interactive drawing.  As such you can't really manipulate the image data interactively, as you would have to modify the original source data first.

To access the actual bitmap data, you need to get the appropriate NSImageRep instance with the representations method.  This will give you an NSArray of NSImageRep subclasses.  The one you'd want is the NSBitmapImageRep.

An NSBitmapImageRep can be created from a specified rectangle by the NSView class.  So you could draw your image into the NSView, perform drawing operations on it, then make a new NSBitmapImageRep.  You could then add that to a new NSImage using the initWithData: method.  I couldn't find any other way to do it.

This is a pretty roundabout way to do onscreen bitmap manipulation.  NSImage is really primarily for getting a representation of an image into an NSView.  NSview has most of the tools you need to manipulate its contents.  For further control you could use an NSQuickTimeView or an NSOpenGLView (my favorite).

Anyway, thats all I could figure out.  I'm sure somebody else knows better than me.

If you don't use Cocoa Browser, I highly recommend it.  It provides an easy way to lookup every Cocoa class and its methods, with links programming topics in the developer help pages:

Cocoa Browser

Unfortunately, it is a little out of date, so some of the newer classes and features might not be listed, but I have found it indispensable for getting a grasp on the Cocoa hierarchy.

Last edited by Metacell (2007-11-15 11:09 am)


Ho Eyo He Hum

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson