我的应用程序需要从加载的 webview 中获取屏幕截图。图像保存时偶尔会出现一个错误。consol 日志如下:
2013-06-04 20:12:33.093 iBookMark[5895:707] thumbnail img save over
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
ImageIO: <ERROR> CGImageSourceCreateWithData data parameter is nil
2013-06-04 20:12:48.987 iBookMark[5895:707] [IMKInputSession activate] exception caught.
IMKInputSession: <IMKInputSession: 0x102124cc0> --
NSPortTimeoutException : connection timeout: did not receive reply
2013-06-04 20:12:53.989 iBookMark[5895:707] [IMKInputSession setValue:forTag:] exception caught.
NSPortTimeoutException : connection timeout: did not receive reply
为什么这个错误可能会发生以及如何修复它?谢谢。
更新:这是我的截图代码。
/*the sender is a webView,this function is called in the
WebView's delegate method naming webView: didFinishLoadForFrame:.*/
[sender setMediaStyle:@"screen"];
[sender lockFocus];
NSData* data = [webView dataWithPDFInsideRect:[webView bounds]];
if (data == nil) {
return;
}
[sender unlockFocus];
[sender setMediaStyle:@"savedMediaStyle"];
NSImage *img = [[NSImage alloc] initWithData:data];
[img setCacheMode:NSImageCacheNever];
NSData* imageData = [img TIFFRepresentation];
NSImage* tmpImg = [[NSImage alloc] initWithData:imageData];
[img release];
NSData* pngData = [NSImage compressImage:tmpImg size:NSMakeSize(SmallThumbnailWidth, SmallThumbnailHeight) factor:0.2];
[tmpImg release];
NSString* thumbnailPath = [PathManager getThumbnailPath];
NSString* imageFilePath = [NSString stringWithFormat:@"%@/%ld.png",thumbnailPath,bookmark.bmId];
[pngData writeToFile:imageFilePath atomically:NO];