Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

quicklook - Why does QLPreviewRequestSetDataRepresentation on Mavericks return error " CGImageCreate: invalid image size: 0 x 0" for png

My quick look generator used to work properly but is now broken.
Is it a bug or am I doing something wrong?

Here’s my code:

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, 
                               CFURLRef url, CFStringRef contentTypeUTI, 
                               CFDictionaryRef options) {

    NSDictionary * myDoc = [NSDictionary dictionaryWithContentsOfURL:(NSURL *)url];

        if (myDoc) {

            NSData * pngData = [myDoc valueForKey:@"pngPreview"];

            if (pngData) {

                QLPreviewRequestSetDataRepresentation(preview,(__bridge CFDataRef)pngData,
                                                      kUTTypeImage,NULL);
            }
        }
}

My doc is a normal plist with a png preview stored as data in it.
I checked that pngPreview does contain png data, I created the image and its size was 350×350.

However, I’m constantly getting these errors:

qlmanage[702] : CGImageCreate: invalid image size: 0 x 0.
qlmanage[702:303] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x9e27, name = 'com.apple.tsm.portname' See /usr/include/servers/bootstrap_defs.h for the error codes.
qlmanage[702:303] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x3f2b, name = 'com.apple.CFPasteboardClient' See /usr/include/servers/bootstrap_defs.h for the error codes.
qlmanage[702:303] Failed to allocate communication port for com.apple.CFPasteboardClient; this is likely due to sandbox restrictions

My app is not sandboxed so I don’t think the last 3 errors are important.

I used to use kUTTypePNG but have tried kUTTypeImage to no avail (the docs for QLPreviewRequestSetDataRepresentation says currently supported UTIs are kUTTypeImage, kUTTypePDF, kUTTypeHTML, kUTTypeXML, kUTTypePlainText, kUTTypeRTF, kUTTypeMovie, and kUTTypeAudio).

Other points to consider: The docs state: "The binary of a Quick Look generator must be universal and must be 32-bit only." This page But this page states: "For OS X v10.6 and later, you must build Quick Look generators for both 32- and 64-bit." Which is rather unclear...
How do I set my target?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Facing the same problem I've decided to go an alternate route: use QLPreviewRequestCreateContext to get a context in which to draw my image in:

QLPreviewRequestRef preview; // The preview request passed to GeneratePreviewForURL()
CGImageRef image;  // Create your CGImage however you like
CGSize size = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));
CGContextRef ctxt = QLPreviewRequestCreateContext(preview, size, YES, nil);
CGContextDrawImage(ctxt, CGRectMake(0, 0, size.width, size.height), image);
QLPreviewRequestFlushContext(preview, ctxt);
CGContextRelease(ctxt);

At least that works...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...