本文介绍了为什么Mavericks上的QLPreviewRequestSetDataRepresentation返回错误"CGImageCreate:图片大小无效:0 x 0"对于png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的快速外观生成器曾经可以正常工作,但是现在坏了.
是错误还是我做错了什么?

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

这是我的代码:


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);
            }
        }
}

我的文档是普通的plist,其中将png预览存储为数据.
我检查了pngPreview是否包含png数据,并创建了图像,其尺寸为350×350.

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

我的应用未经过沙箱测试,因此我认为最后3个错误并不重要.

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

我曾经使用过kUTTypePNG,但没有尝试过kUTTypeImage(QLPreviewRequestSetDataRepresentation的文档说,当前支持的UTI是kUTTypeImage,kUTTypePDF,kUTTypeHTML,kUTTypeXML,kUTTypePlainText,kUTTypeRTF,kUTTypeMovie和kUTTypeAudio).

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).

要考虑的其他要点:文档状态:"Quick Look生成器的二进制文件必须是通用的,并且只能是32位." 此页面但是此页面指出: 对于OS X v10.6和更高版本,必须为32位和64位都构建Quick Look生成器."哪个还不清楚...
我该如何设定目标?

Other points to consider:The docs state:"The binary of a Quick Look generator must be universal and must be 32-bit only." This pageBut 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?

推荐答案

面对相同的问题,我决定采用另一种方法:使用QLPreviewRequestCreateContext获取在其中绘制图像的上下文:

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);

至少行得通...

这篇关于为什么Mavericks上的QLPreviewRequestSetDataRepresentation返回错误"CGImageCreate:图片大小无效:0 x 0"对于png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 23:38