• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
formatting to 72dpi
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

formatting to 72dpi


  • Subject: formatting to 72dpi
  • From: Josh Anon <email@hidden>
  • Date: Sat, 25 Oct 2003 14:04:39 -0700

This should be an easy one :)
I've got an image at a higher dpi, and I want to make it 72dpi to save to a file. I started with the code from Karelia:
-(NSImage*)normalizeSize {
NSBitmapImageRep *theBitmap = nil;
NSSize newSize;
NSArray *reps = [self representations];
int i;

for (i = 0 ; i < [reps count] ; i++ )
{
NSImageRep *theRep = [reps objectAtIndex:i];
if ([theRep isKindOfClass:[NSBitmapImageRep class]])
{
theBitmap = (NSBitmapImageRep *)theRep;
break;
}
}
if (nil != theBitmap)
{
newSize.width = [theBitmap pixelsWide];
newSize.height = [theBitmap pixelsHigh];
if ((newSize.width == [self size].width) && (newSize.height == [self size].height)) {
return self;
}
[theBitmap setSize:newSize];
[self setScalesWhenResized:YES];
[self setSize:newSize];
}

return self;
}

which works nicely if I'm displaying an image. However, when I was saving it to a file, this didn't work (theBitmap was the right size at the end of the method and the wrong size immediately on return). So, I tried this:

- (NSImage *)normalizeSize {
NSBitmapImageRep *theBitmap = nil;
NSImage *newImage = nil;
NSArray *reps = [self representations];
int i;

for (i = 0 ; i < [reps count] ; i++ )
{
NSImageRep *theRep = [reps objectAtIndex:i];
if ([theRep isKindOfClass:[NSBitmapImageRep class]])
{
theBitmap = (NSBitmapImageRep *)theRep;
break;
}
}
if (nil != theBitmap)
{
int width = [theBitmap pixelsWide];
int height = [theBitmap pixelsHigh];
int spp = [theBitmap samplesPerPixel];
int bps = [theBitmap bitsPerSample];
BOOL hasAlpha = [theBitmap hasAlpha];
BOOL isPlanar = [theBitmap isPlanar];
NSString *csn = [theBitmap colorSpaceName];

NSBitmapImageRep *r2 = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:bps
samplesPerPixel:spp
hasAlpha:hasAlpha
isPlanar:isPlanar
colorSpaceName:csn
bytesPerRow:width * (spp * bps)/8
bitsPerPixel:bps * spp];
memcpy([r2 bitmapData], [theBitmap bitmapData], width * height * spp * (bps/8));
newImage = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
[newImage addRepresentation:r2];
[r2 release];
}
return [newImage autorelease];
}

which works nicely if I'm saving to a file, but mangles things that go to the screen.

I've spent enough time on this, that I'm just stumped and asking for help. Anyone know of a method to normalize to 72dpi for both display and saving?

Thanks,
Josh

--
//email@hidden || http://www.areax.net
"More piggies Gir! I demand piggies" - Invader Zim
_______________________________________________
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.

  • Prev by Date: Re: XCode for Jaguar?
  • Next by Date: XCode/Panther issues
  • Previous by thread: NSController/binding question?
  • Next by thread: XCode/Panther issues
  • Index(es):
    • Date
    • Thread