Re: NSImage representations
Re: NSImage representations
- Subject: Re: NSImage representations
- From: Jeremy Rotsztain <email@hidden>
- Date: Mon, 9 Jul 2007 00:45:39 -0400
It turns out that it's not a problem with the image, but rather a
malformed loop that runs through the bytes of the image. Ooops.
I've got it working now, but have noticed some inconsistencies when
my source image is scaled. For example, only half of the image will
be 'quantized'.
NSSize imgNewSize = NSMakeSize(320, 240);
[ myImage setScalesWhenResized: YES];
[ myImage setCacheMode: NSImageCacheNever];
[ myImage setSize:imgNewSize];
Is this because the resolution of the NSBitmapImageRep that I've
created is based resolution of the source image's representation and
not it's scaled one?
- (NSImage *) quantizeImage: (NSImage *) myImage {
NSBitmapImageRep *sourceRep = [ NSBitmapImageRep imageRepWithData:
[myImage TIFFRepresentation]];
...
}
Thanks,
Jeremy
Please post the tiff representation of the NSImage objects it
doesn't work on. It sounds like the bitmaprep isn't being created
and bitmapData is returning NULL. You might try calling +
[NSImageRep canInitWithData] on the tiff representation to see if
that's what's causing it. Additionally, if you load 8-bit or 16-bit
images, that code will fail, since it tries to set 3 bytes for each
pixel.
The way I generally do it, to avoid TIFFRepresentation and ensure
that all of my bitmap image reps are 32 ARGB is create the bitmap
rep explicitly, then lock focus onto it (there's a method for that
in NSGraphicsContext) and draw the NSImage on it. It may be a bit
slower, but I've found that it ensures that you know the exact
details of the bitmap data and is overall more future proof. It's
still far quicker than setPixel.
- Dorian
_______________________________________________
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