Re: Resolution of JPEG
Re: Resolution of JPEG
- Subject: Re: Resolution of JPEG
- From: Dan Wood <email@hidden>
- Date: Fri, 19 Oct 2001 10:00:45 -0700
Here's a category that I use for "normalizing" the size of an
image. What this does is to look through an NSImage's
representations for a NSBitmapImageRep. Then, it adjusts the size
of the bitmap and the image to be the pixels wide and pixels high.
You could certainly simplify this if you knew you were always
dealing with a bitmap; you could just get the first NSImageRep.
But this should give you the idea.
Oh yeah -- this *changes* the given image and bitmap. If you wanted
to get a copy and leave the original alone, you'd need to make
appropriate changes here.
Dan
@implementation NSImage ( misc )
/*" If a bitmap image, fix the size of the bitmap so that it is
equal to the exact pixel dimensions. "*/
- (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];
[theBitmap setSize:newSize];
[self setSize:newSize];
}
return self;
}
@end
On Thursday, October 18, 2001, at 09:58 PM, Jeff LaMarche wrote:
I'm instantiating an NSImage with an NSData object that contains a
JPEG image. Most of the JPEG images are set to screen resolution,
but sometimes they are set to a higher value. When the resolution
is set higher, the images display smaller in the NSImageView that
I'm using to show them in. I'd like the images to all show at
screen resolution - each image pixel corresponds to one screen
pixel - but don't want to change the source data.
I don't see any method in NSImage for changing the resolution. How
do I do this? Do I need to create another representation for the
image, or is there a better way to do this?
Jeff
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
--
Dan Wood
email@hidden
http://www.karelia.com/
http://www.bikealameda.org/
Mac OS X Developer: Online Resume:
http://www.karelia.com/resume.html