Re: Forcing an NSImage to render it's NSImageRep's ?
Re: Forcing an NSImage to render it's NSImageRep's ?
- Subject: Re: Forcing an NSImage to render it's NSImageRep's ?
- From: Peter Ammon <email@hidden>
- Date: Fri, 15 Aug 2008 14:52:57 -0700
On Aug 15, 2008, at 11:44 AM, Matthew Mashyna wrote:
I want to interlace some images on a column by column basis. My
initial idea was to open them all as NSImages, rotate them 90
degrees, interlace them row by row using the image rep's row data
and then rotate the final image back 90 degrees.
I can't seem to force my NSImage to draw into an image rep after I
rotate it unless I take the trouble to display it first. I know that
this isn't really what NSImage is for but it would save be a bunch
of trouble over having to do it with Quartz. I tried a few things
but I can't seem to push it to actually render the bitmap rep.
Is there an official way to push NSImage to render it's NSImageReps
without having to wait for it to be displayed in an NSImageView ? I
don't want to see them in views, I want to mess with them and
generate a TIFF file.
Am I stuck using Quartz, then ?
You should not depend on how - or whether - NSImage generates bitmap
reps. It may use a variety of pixel formats in different situations,
and you don't want to have to handle them all. It may also change the
reps it chooses to create, and whether and how it caches.
The fastest (as in performance) way to do this would probably be to
use Core Image. It would be straightforward to write your own kernel
to do this transformation. Assuming your input images have the same
dimensions and you want your output image to be twice as wide, you
might also try a non-interpolated horizontal scale of each image,
followed by CIBlendWithMask, to get a result image with columns taken
alternately from both input imges.
If you are set on twiddling bits by hand, I think this is the best path.
- Make an NSBitmapImageRep with the dimensions and pixel format you
want to use.
- Use +[NSGraphicsContext graphicsContextWithBitmapImageRep:] to make
a graphics context to draw into
- Save the current graphics context, and set your new context as
current with [NSGraphicsContext setCurrentContext:]
- Draw your image
- Restore the context you saved
- Twiddle the bits in the bitmap image rep
- Make a new NSImage, and add the bitmap rep to it as a representation
-Peter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden