NSBMPFileType and resolution setting
NSBMPFileType and resolution setting
- Subject: NSBMPFileType and resolution setting
- From: Prady K <email@hidden>
- Date: Mon, 24 Oct 2005 19:22:43 -0700
Hi
I have this piece of code that is used to save a image in different
formats with a given resolution. It works fine for all formats except
for the BMP format (NSBMPFileType). For this case it always sets the
resolution to 72dpi.
//get the image of the opened filed
NSImage *theImage = [[NSImage alloc]
initWithContentsOfFile:m_pOpenedFile];
if (theImage != nil)
{
[theImage autorelease];
//get the bitmap image rep
NSBitmapImageRep *theBmapRep = [theImage
bestRepresentationForDevice:nil];
//make a copy of the bitmap image rep to resave the image
NSBitmapImageRep *theNewBmapRep = [theBmapRep copy];
//get the desired resolution to save the image in
float theXRes = [m_pXResField floatValue];
float theYRes = [m_pYResField floatValue];
//Generate the new size for the resaved image. Literally changing
the size is like changing the resolution of the image.
NSSize theNewSize = NSMakeSize(72*([theBmapRep pixelsWide]/theXRes),
72*([theBmapRep pixelsHigh]/theYRes));
[theNewBmapRep setSize:theNewSize];
//Save the file
NSData *theFileData =[theNewBmapRep representationUsingType:
[m_pFileFormat indexOfSelectedItem] properties:nil];
NSSavePanel *thePanel = [NSSavePanel savePanel];
NSString *theFilename = [NSString stringWithFormat:@"ResavedFile.%
@", [self getExtension]];
if ([thePanel runModalForDirectory:@"~/Desktop" file:theFilename] ==
NSOKButton)
[theFileData writeToFile:[thePanel filename] atomically:YES];
[theNewBmapRep release];
}
Any ideas why it is not setting the resolution for the BMP file type?
Also is there a workaround for this?
TIA
Prady K
_______________________________________________
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