NSView -> BMP file
NSView -> BMP file
- Subject: NSView -> BMP file
- From: "Erik J. Barzeski" <email@hidden>
- Date: Fri, 12 Jul 2002 14:09:32 -0400
Hi,
I've got a custom subclass of NSView that I'd like to save to a bitmap file.
I've implemented methods that properly save the file as PDF, TIFF, JPEG,
GIF, and PNG, but BMP is eluding me.
I've looked at the available documentation (a few times) and tried various
versions of what I'll paste below, none of which have worked. Some return no
data, some return the wrong sort of data, and so on. It's possible that I'm
skipping a step, in expecting data back when I should be looking to get a
pointer to the head of a block of bitmap data...
At any rate, here's code that works for PNG, for example:
NSData *data = [myView dataWithPDFInsideRect:[myView bounds]];
:
:
else if([[[sheet filename] pathExtension] isEqualToString:@"png"])
{
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWith
Data:[[[NSImage alloc] initWith
Data:data] TIFFRepresentation]];
NSNumber *ditherTransparency = [NSNumber numberWithBool:YES];
NSDictionary *propertyDict = [NSDictionary
dictionaryWithObject:ditherTransparency forKey:NSImageInterlaced];
data = [imageRep representationUsingType:NSPNGFileType
properties:propertyDict];
}
I then:
[data writeToFile:[sheet filename] atomically:YES];
The PNG one above and the other blocks I have work for the five image
formats. However, BMP fails miserably regardless of what I've tried.
This line in particular seems awkward:
[imageRep representationUsingType:NSBMPFileType properties:propertyDict];
Given these file types:
NSTIFFFileType, NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType
And these possibilities for the dictionary you pass into
representationUsingType:properties: (snipped a few things, like
APPKIT_EXTERN)
NSString* NSImageCompressionMethod; // TIFF (NSTIFFCompression in NSNumber)
NSString* NSImageCompressionFactor; // TIFF/JPEG (float in NSNumber)
NSString* NSImageDitherTransparency; // GIF output (BOOL in NSNumber)
NSString* NSImageRGBColorTable; // GIF input/output (packed RGB in NSData)
NSString* NSImageInterlaced; // PNG output (BOOL in NSNumber)
NSString* NSImageColorSyncProfileData; // TIFF input/output (NSData)
TIFFs, JPEGs, GIFs, PNGs, and of course the natively supported PDF have
information for the properties: dictionary. NSBMPFileType does not...
I'm quite sure I'm overlooking something silly, so if anyone could point me
in the right direction it'd be appreciated tremendously... Thanks.
--
Kindest regards,
Erik J. Barzeski
There are two great secrets to success in life.
The first is to not tell everything you know.
###################################################################
Email: erik@(anything below) AIM: iacas
http://iacas.org http://weims.net
http://techstra.net http://barzeski.com
http://cocoadevcentral.com http://soundsetcentral.com
http://freshlysqueezedsoftware.com http://applescriptcentral.com
###################################################################
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.