Re: CIImage - saving the file?
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