プレビュー画像のサイズ情報を渡す
追加情報を辞書で渡す
プレビュー画像の表示ですが、画像のサイズとは無関係な大きさで表示されてしまい、ビットマップ画像ではあらが目立ちます。作成した画像のサイズで表示してもらえないものでしょうか?
QLPreviewRequestSetDataRepresentationの第四パラメータは追加情報を表す辞書です。先ほどは何も渡していませんでしたが、辞書に追加できる情報にはプレビューの幅と高さがあるので、これを辞書に入れて渡してみます。
OSStatus GeneratePreviewForURL(
void *thisInterface,
QLPreviewRequestRef preview,
CFURLRef url,
CFStringRef contentTypeUTI,
CFDictionaryRef options)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSBezierPath *bp;
NSSize imageSize = NSMakeSize(300,200);
NSImage *image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:300],kQLPreviewPropertyWidthKey,
[NSNumber numberWithInt:200],kQLPreviewPropertyHeightKey,
nil];
[image lockFocus];
[[NSColor whiteColor] set];
[NSBezierPath fillRect:NSMakeRect(0,0,300,200)];
bp = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(90,40,120,120)];
[[NSColor redColor] set];
[bp fill];
[image unlockFocus];
CFDataRef imageData = (CFDataRef)[image TIFFRepresentation];
QLPreviewRequestSetDataRepresentation(
preview,imageData,kUTTypeImage,(CFDictionaryRef)dict);
[pool release];
return noErr;
}
ビルドして実行すると、以下のウィンドウが表示されました。小さくなっていますが、大きく表示される事もあったので、完璧ではないのかもしれません。


HOME
前のページへ