• 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
CIImage - saving the file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CIImage - saving the file?


  • Subject: CIImage - saving the file?
  • From: Nick Morris <email@hidden>
  • Date: Wed, 18 May 2005 13:50:15 +0100

Hi,

I think I am missing something simple in trying to understand core image. I have read most of the online material, I have googled the subject, I have looked at the supplied example and yet I cannot find a simple answer..... I get the core image code to work great. However, when I come to save I go through this long winded conversation / manipulation process.

I can create and manipulate a core image with no problems. However, when I come to save the image I am using some awful code which I am sure is not right. I have put the code below. The relevant part is after the comment: // IT IS FROM HERE THAT I AM NOT HAPPY WITH THE CODE!!!!!!

Thanks in advance,

Nick

------------------------------------------------

NSImage *sourceImage = [[NSImage alloc] initWithContentsOfFile:oldPathname];
CIImage *theImage;
NSDictionary *theFileSaveDictionary = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat: ([jpegQualityfloatValue] / 100.0)], NSImageCompressionFactor, nil];
NSData *theImageData;
NSBitmapImageRep *theBitMapToBeSaved;
CIFilter *myFilter;
NSURL *url;
NSCIImageRep *imgRep;
NSImage *resultImage;
NSSize newSize;
CGRect imageRect;
float yscale;


// set up the CIImage
url = [NSURL URLWithString:oldPathname];
theImage = [CIImage imageWithContentsOfURL:url];

// get the CGRect for the image
imageRect = [theImage extent];

// set scaling factor (i.e. reduce size to 10% of original)
yscale = 0.1;

// set the new size (height and width for the image)
newSize.width = imageRect.size.width * yscale;
newSize.height = imageRect.size.height * yscale;

// set up a rescaling filter
myFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];

// set up the parameters for the scaling filter
[myFilter setValue:[NSNumber numberWithFloat:yscale] forKey:@"inputScale"];
[myFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputAspectRatio"];


// load the image and apply the filter
[myFilter setValue:theImage forKey:@"inputImage"];

// output the new CIImage (i.e. the scaled image
theImage = [myFilter valueForKey:@"outputImage"];

// IT IS FROM HERE THAT I AM NOT HAPPY WITH THE CODE!!!!!!

// create a NSCIImageRep image rep
imgRep = [NSCIImageRep imageRepWithCIImage:theImage];

// create an NSImage of the size required to hold the new rep
resultImage  = [[NSImage alloc] initWithSize:newSize];

// add the image rep to the NSImage
[resultImage addRepresentation: imgRep];

// TIFF the NSImage (this step seems slow)
theImageData = [resultImage TIFFRepresentation];

// NSBitmapImageRep the NSINage and save
theBitMapToBeSaved = [NSBitmapImageRep imageRepWithData:theImageData];
[[theBitMapToBeSaved representationUsingType:NSJPEGFileType properties:theFileSaveDictionary] writeToFile:newPathname atomically:NO];


_______________________________________________
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


  • Follow-Ups:
    • Re: CIImage - saving the file?
      • From: Troy Stephens <email@hidden>
  • Prev by Date: Re: CoreData issue when updating a file format
  • Next by Date: Re: Manually Editing Preferences
  • Previous by thread: Re: KVO returning nil for old values, and mmalc's Graphics Bindings example
  • Next by thread: Re: CIImage - saving the file?
  • Index(es):
    • Date
    • Thread