Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing Core Image into a PDF Context




On Jun 20, 2005, at 11:21 AM, John Harper wrote:

On Jun 18, 2005, at 1:13 AM, Scott Thompson wrote:

Upon trying to draw a CIImage into a PDF context, I was surprised to see that area of the context show up completely black.

Is it the case that you can only render a CIImage into a pixel- based context?


No, it should work with any context, what kind of CIImage are you using?


John

OK... I put my code that tries to draw a CIImage into a PDF context back together again and I'm getting the same result. The resulting PDF is black where the image is supposed to be. The same CIImage drawn to a window works just fine.


I'll put my code in below.

The original application was a carbon application using Core Image (that's why there's an explicit autorelease pool for example.

There's really nothing remarkable (that I know of) about the Beach image. It's just a picture that I took with my digital camera and exported at 640x480. If I adjust the application so that it draws in a Carbon window (inside of an HIView's kEventControlDraw handler into the context passed to me by the OS), the same DrawBlurredImage routine draws a blurry version of my image.

If you have any thoughts about why I can't dump the image into a PDF context. Please let me know.

I'll also put together a bug report and sample app.

Scott

--- begin included code ---

CGImageRef CreateSourceImage()
{
CFURLRef sourceImageURL = CFBundleCopyResourceURL (CFBundleGetMainBundle(), CFSTR("Beach"), CFSTR("jpg"), NULL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL (sourceImageURL, 0);
CFRelease(sourceImageURL);
sourceImageURL = NULL;


CGImageRef sourceCGImage = CGImageSourceCreateImageAtIndex (imageSource,0,0);
CFRelease(imageSource);
imageSource = NULL;


    return sourceCGImage;
}

void DrawBlurredImage(CGContextRef outputContext, const CGRect &viewBounds)
{
// Create an autorelease pool to catch stray objects
NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init];


// Obtain the source image and create a CIImage with that set of pixels
CGImageRef sourceCGImage = CreateSourceImage();
CIImage *sourceCIImage = [CIImage imageWithCGImage: sourceCGImage];


CGRect sourceBounds = CGRectMake(0, 0, CGImageGetWidth (sourceCGImage), CGImageGetHeight(sourceCGImage));

    // We've done with the source image.
    CFRelease(sourceCGImage);
    sourceCGImage = NULL;

// Create a filter and assign the parameters
CIFilter *gaussianBlur = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlur setDefaults];


[gaussianBlur setValue: sourceCIImage forKey: @"inputImage"];
[gaussianBlur setValue: [NSNumber numberWithFloat: 10] forKey: @"inputRadius"];


    // extract the resulting CIImage from the blur filter.
    CIImage *result = [gaussianBlur valueForKey: @"outputImage"];

// Create a CIContext on our graphics context and render the image into it.
CIContext *outputCIContext = [CIContext contextWithCGContext: outputContext options: NULL];
[outputCIContext drawImage: result inRect: viewBounds fromRect: sourceBounds];


    // release the autorelase pool
    [autoreleasePool release];
    autoreleasePool = NULL;
}

void DrawPDFVersion()
{
CGRect mediaRect = CGRectMake(0, 0, 640, 480);
CFURLRef destinationURL = CFURLCreateWithFileSystemPath(NULL, CFSTR("/Users/scott/Desktop/BlurredBeach.pdf"), kCFURLPOSIXPathStyle, false);


CGContextRef outputContext = CGPDFContextCreateWithURL ( destinationURL, &mediaRect, NULL);
CGContextBeginPage(outputContext, &mediaRect);


    DrawBlurredImage(outputContext, mediaRect);

    CGContextEndPage(outputContext);
    CFRelease(outputContext);
    CFRelease(destinationURL);
}

int main(int argc, char* argv[])
{

    DrawPDFVersion();

}


_______________________________________________ Do not post admin requests to the list. They will be ignored. Quartz-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden
References: 
 >Drawing Core Image into a PDF Context (From: Scott Thompson <email@hidden>)
 >Re: Drawing Core Image into a PDF Context (From: John Harper <email@hidden>)
 >Re: Drawing Core Image into a PDF Context (From: Scott Thompson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.