我的应用程序需要从加载的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
为什么这个bug可能会发生以及如何修复它?谢谢。
更新: 这是我的截图代码。
/*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];
答案 0 :(得分:-3)
我想我已经找到了这个问题的答案。我创建了一个NSImage
对象,发现它在使用时可能会变为零。这是ImageIO Error
的原因。我已经修复了这个错误。