如何进行cgimageref
-
02-10-2019 - |
题
我正在编写一个快速插件。好吧,一切都起作用。只想尝试它会变得更好;)。因此问题。
这是返回缩略图图像的函数,我现在正在使用。
QLThumbnailRequestSetImageWithData(
QLThumbnailRequestRef thumbnail,
CFDataRef data,
CFDictionaryRef properties);
);
现在,我正在创建一个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);
);
我有一种感觉,将cgimage传递到QL而不是TIFF数据将有助于加速问题。但是 - 我以前从未使用过CG上下文。我知道,文档就在那里:),但是无论如何 - 任何人都可以举个例子,如何将NSATRIB的字符串转变为CgimageRef。一个例子是阅读文档的10倍;)
任何帮助都赞赏。提前致谢!
不隶属于 StackOverflow