Re: NSImage is a pain
Re: NSImage is a pain
- Subject: Re: NSImage is a pain
- From: SA Dev <email@hidden>
- Date: Thu, 23 Jun 2005 16:53:51 -0400
Erik:
Thanks for this! This thread (though it started out as an outright
rant) has been pretty illuminating. I admit to the same frustration
with trying to figure out the ins and outs of *creating* images using
NSImage. I mostly just copied code examples without really
understanding them and hoped for the best (bad programmer, BAD
programmer!).
On Jun 23, 2005, at 4:47 PM, Erik Buck wrote:
NSImage is an example of the Facade design pattern.
The Facade design pattern provides a unified interface to a set of
interfaces in a subsystem. Façade defines a higher-level interface
that makes the subsystem easier to use.
NSImage provides a unified interface for loading and using images
that may be bitmap based or vector based. In addition, NSImage
provides features for creation and preservation of multiple
underlying image representations so that for example, the same
image can be used at multiple resolutions and/or a vector
representation is preserved even if a bitmap representation
generated from the vector representation is used for performance
reasons.
If all you want is a bitmap at one size and one resolution in a
particular format, NSImage does not seem to add any value.
The purpose of NSImage is to hide the details for you so that you
can use lots of different underlying representations of images
interchangeably. Furthermore, because NSImage supports lots of
different representations of what an image is, something like
getting the color of a "pixel" is tricky. The underlying image may
be vector based and may be device independent so that there are no
"pixels."
Furthermore, Quartz and Display postscript before it provide a
unified imaging model that supports alpha and compositing
operations natively. Because NSImage is built to use Quartz, image
formats like EPS, PDF, and tiff which support alpha and are
compatible with the unified support provided by Quartz are
naturally best used. Something backwards and primitive like
wanting to declare the color "white" to be fully transparent in an
arbitrary gif image which does not inherently store alpha data is
not a reasonable thing to expect in a facade for general
interactions with images.
I suspect that using Quick Time or vImage/Core Image to perform
efficient manipulation of bitmap pixel data may be more what the
original poster wants.
Now, in my case, if I had a lot of gif images with white
backgrounds and I wanted the backgrounds to be transparent, the
first thing I would do is convert the gif images to a format like
tga, tiff, or png that provides support for transparency. Then I
would convert every pixel that is color white to a pixel that is
color clear. Then I would use the converted bitmaps with NSImage.
If I had few such images, I would just use Photoshop or Corel Photo
Paint to convert the images. If I had many, I would look for a
utility (graphic converter ?) and/or write QuickTime or Core Image
code to do the conversion and then never look back.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40silentalcove.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden