我正在编写一个快速插件。好吧,一切都起作用。只想尝试它会变得更好;)。因此问题。
这是返回缩略图图像的函数,我现在正在使用。

QLThumbnailRequestSetImageWithData(
QLThumbnailRequestRef thumbnail,
CFDataRef data,
CFDictionaryRef properties);
);

http://developer.apple.com/mac/library/documentation/userexperience/referenion/reference/qlthumbnailrequest_ref/reference/reference/reeference.htmll#/apple_reff/c/func/func/func/qlthumb/qlthumbnailrequestsetemimagewithdata

现在,我正在创建一个TIFF->将其封装到NSDATA中。一个例子

// Setting CFDataRef
CGSize thumbnailMaxSize = QLThumbnailRequestGetMaximumSize(thumbnail);
NSMutableAttributedString *attributedString = [[[NSMutableAttributedString alloc] 
                                                   initWithString:@"dummy" 
                                                   attributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                               [NSFont fontWithName:@"Monaco" size:10], NSFontAttributeName, 
                                                               [NSColor colorWithCalibratedRed:0.0 green:0.0 blue:0.0 alpha:1.0], NSForegroundColorAttributeName, 
                                                               nil]
                                                   ] autorelease];
NSImage *thumbnailImage = [[[NSImage alloc] initWithSize:NSMakeSize(thumbnailMaxSize.width, thumbnailMaxSize.height)] autorelease];
[thumbnailImage lockFocus];
[[NSColor whiteColor] set];
NSRectFill(NSMakeRect(0, 0, thumbnailMaxSize.width, thumbnailMaxSize.height));
[attributedString drawInRect:NSMakeRect(0, 0, thumbnailMaxSize.width, thumbnailMaxSize.height)];
[thumbnailImage unlockFocus];
(CFDataRef)[thumbnailImage TIFFRepresentation]; // This is data

// Setting CFDictionaryRef
(CFDictionaryRef)[NSDictionary dictionaryWithObjectsAndKeys:@"kUTTypeTIFF", (NSString *)kCGImageSourceTypeIdentifierHint, nil ]; // this is properties

但是,快速浏览提供了返回缩略图图像的另一个功能,即

QLThumbnailRequestSetImage(
QLThumbnailRequestRef thumbnail,
CGImageRef image,
CFDictionaryRef properties);
);

http://developer.apple.com/mac/library/documentation/userexperience/reference/qlthumbnailrequest_ref/reference/Rereference/Rereference.htmll#/apple_reff/c/func/func/func/func/qlthumbnailrequestsetemimage

我有一种感觉,将cgimage传递到QL而不是TIFF数据将有助于加速问题。但是 - 我以前从未使用过CG上下文。我知道,文档就在那里:),但是无论如何 - 任何人都可以举个例子,如何将NSATRIB的字符串转变为CgimageRef。一个例子是阅读文档的10倍;)
任何帮助都赞赏。提前致谢!

有帮助吗?

解决方案

任何人都可以举个例子,如何将NSATRIB的字符串转变为CgimageRef。

您不能将字符串变成图像;它们是两种完全不同的数据,一个是二维的(随着时间的时间),而另一个是至下三维的(x和y上的颜色)。

您需要做的是 字符串并产生图形的图像。这就是您现在使用的Nsimage:创建图像并将字符串绘制到其中。

您正在询问创建CGIMAGE。创建一个 位图上下文, , 使用 核心文字 将字符串绘制到其中,创建位图上下文内容的图像是一种方法。

但是,假设您需要Snow Leopard,您已经更接近另一个解决方案了。而不是要求NSimage进行TIFF代表,而是 要求它.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top