• 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
Reduce the size of an NSImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reduce the size of an NSImage


  • Subject: Reduce the size of an NSImage
  • From: Simon Raisin <email@hidden>
  • Date: Mon, 31 May 2010 08:38:43 -0400

Hi,


I am trying to reduce the size of an NSImage by 50% and then save the
reduced image out to disk.  The following code does not reduce the image.
 Should I be going about this a different way?


Thanks!

Simon



NSImage* inputImage = [[NSImage alloc] initWithContentsOfFile:[fileNames
objectAtIndex:0]];


NSSize halfSize = [inputImage size];

halfSize.height = (int)(halfSize.height / 2);

halfSize.width  = (int)(halfSize.width  / 2);


[inputImage setScalesWhenResized:YES];

[inputImage setSize:halfSize];



NSBitmapImageRep* imageRepx = [NSBitmapImageRep
imageRepWithData:[inputImage TIFFRepresentation]];

NSDictionary *imagePropsx = [NSDictionary dictionaryWithObject:[NSNumber
numberWithFloat:0.9]


 forKey:NSImageCompressionFactor];

NSData* outputImageDatax = [imageRepx representationUsingType:NSJPEGFileType
properties:imagePropsx];



[outputImageDatax writeToFile:@"resizedimage.jpg" atomically:YES];
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Reduce the size of an NSImage
      • From: Steve Christensen <email@hidden>
    • Re: Reduce the size of an NSImage
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Re: Which color space?
  • Next by Date: Re: Which color space?
  • Previous by thread: Re: Which color space?
  • Next by thread: Re: Reduce the size of an NSImage
  • Index(es):
    • Date
    • Thread