• 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
Re: Resolution of JPEG
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Resolution of JPEG (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: Re: Security Issue ... was[What happens to ...]
  • Next by Date: Re: Security Issue ... was[What happens to ...]
  • Previous by thread: Resolution of JPEG
  • Next by thread: Narrowing in on NSTableView problem..
  • Index(es):
    • Date
    • Thread