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

Re: CIImage - saving the file?


  • Subject: Re: CIImage - saving the file?
  • From: Troy Stephens <email@hidden>
  • Date: Wed, 18 May 2005 10:27:05 -0700

You can create an NSBitmapImageRep from a CIImage more directly, by instantiating a new NSBitmapImageRep and compositing the CIImage into it:


// Create a new NSBitmapImageRep.
theBitMapToBeSaved = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:newSize.width pixelsHigh:newSize.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:0 bitsPerPixel:0];


// Create an NSGraphicsContext that draws into the NSBitmapImageRep. (This capability is new in Tiger.)
NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:theBitMapToBeSaved];


// Save the previous graphics context and state, and make our bitmap context current.
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: nsContext];


// Get a CIContext from the NSGraphicsContext, and use it to draw the CIImage into the NSBitmapImageRep.
[[nsContext CIContext] drawImage:ciImage atPoint:imageDestinationRect.origin fromRect:extent];


// Restore the previous graphics context and state.
[NSGraphicsContext restoreGraphicsState];


It's about the same amount of source code as what you had, but avoids the unnecessary allocation of the intermediate "TIFFRepresentation" data and NSImage.


You can then write the NSBitmapImageRep to a file just as you were doing before:

[[theBitMapToBeSaved representationUsingType:NSJPEGFileType properties:theFileSaveDictionary] writeToFile:newPathname atomically:NO];

-- Troy Stephens Cocoa Frameworks Apple Computer, Inc.

On May 18, 2005, at 5:50 AM, Nick Morris wrote:
// 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



_______________________________________________
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: Shawn Erickson <email@hidden>
References: 
 >CIImage - saving the file? (From: Nick Morris <email@hidden>)

  • Prev by Date: Re: NEWBIE: Why use protocols?
  • Next by Date: Re: NEWBIE: Why use protocols?
  • Previous by thread: CIImage - saving the file?
  • Next by thread: Re: CIImage - saving the file?
  • Index(es):
    • Date
    • Thread