• 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
how to get image resolution from NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to get image resolution from NSImage


  • Subject: how to get image resolution from NSImage
  • From: 김경옥 <email@hidden>
  • Date: Fri, 18 Mar 2005 21:01:49 +0900

Hi,
 
I'm working on an image editor that has a feature to resize the image size including resolution.
I calculate the image resolution by the difference between the size and pixels of NSBitmapImageRep.
 
If the NSBitmapImageRep says size = {514, 388} and pixels = 143x108,
it means resolution = 72 * pixel/width = 72 * 143/514 = about 20 dpi.
 
But when I change the resolution of an image to about 10 or 5 (very small dpi) from any resolution greater than those dpi, the resolution is not saved as inputted.
 
If I check the NSBitmapImageRep after saving, the size and pixels of NSBitmapImageRep become the same size.
That makes me I get only 72 dpi from the NSBitmpaImageRep even though its resolution is 10 or 5.
When I check it in 'Image Size' panel in PhotoShop, the resolution of the image is changed to inputted dpi.
 
I think there is any other way to calculate image resolution except by size and pixels of NSBitmapImageRep.
 
Please let me know if you know what the problem is or there is any other information I can get from NSImage for calculating image resolution.
When I save the image with different resolution, I use the code below,
===================================================================================================
  theBitmap = [[savedImage representations] objectAtIndex:0];
 
  NSSize newSize;
  newSize.width = 72 *  newWPix/newRes;
  newSize.height = 72 * newHPix/newRes;
  [theBitmap setPixelsWide:newWPix];
  [theBitmap setPixelsHigh:newHPix];
       
         
  NSImage *temp_image = [[NSImage alloc] init];
  
  [temp_image addRepresentation:theBitmap];
  
  NSImage* temp_image2;
  
  NSSize temp_size;
  temp_size.width = [theBitmap pixelsWide];
  temp_size.height = [theBitmap pixelsHigh];
  temp_image2 = [[NSImage alloc] initWithSize:temp_size];
  [temp_image2 lockFocus];
  
 [temp_image drawInRect:NSMakeRect(0,0,temp_size.width,temp_size.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];

  [temp_image2 unlockFocus];
        
  NSBitmapImageRep* TIFFRep;
  
  TIFFRep = [[NSBitmapImageRep alloc] initWithData:[temp_image2 TIFFRepresentation]];
  
  [TIFFRep TIFFRepresentation];
  
  [TIFFRep setSize:newSize];
 
  theBitmap = TIFFRep;
 
  NSDictionary *jpegProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWith ....;
  NSDate *newData = theBitmap representationUsingType:NSJPEGFileType ....;
  ...
===================================================================================================
Thanks.
 _______________________________________________
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

  • Prev by Date: NSStatusItem having action and menu
  • Next by Date: NSDate and binding to pattern display value
  • Previous by thread: Re: NSStatusItem having action and menu
  • Next by thread: Re: how to get image resolution from NSImage
  • Index(es):
    • Date
    • Thread