2009-09-29 4 views
0

이미지를 다운로드하고 인쇄하는 웹킷 플러그인을 작성하고 있습니다. 정확한 데이터가 다운로드되고 NSImage의 치수가 올바른지 확인했습니다. 아쉽게도 이미지가 포함 된 NSImageView는 프린터로 전송 된 문서 나 내용보기의 유일한 하위보기로보기를 포함하는 창에는 아무 것도 표시하지 않습니다. 여기 내 코드는 다음과 같습니다Web Kit 플러그인에서 NSImageView가 비어 있습니다.

-(void)printImageAtURL:(NSString*)imageUrl{ 
    NSURLResponse *response; 
    NSError *error = nil; 

    NSURL *url = [NSURL URLWithString:imageUrl]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20]; 
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
    if(error) 
     return; 
    //Data is the correct length 
    NSImage *image = [[NSImage alloc] initWithData:data]; 

    NSSize imageSize = [image size]; 
    //imageSize is correct dimensions 

    NSRect viewRect = NSMakeRect(0, 0, imageSize.width, imageSize.height); 

    NSImageView *imageView = [[NSImageView alloc] initWithFrame:viewRect]; 
    [imageView setImage:image]; 
    [image release]; 

    NSPrinter *printer = [NSPrinter printerWithName:[[NSPrinter printerNames] objectAtIndex:0]]; 
    NSPrintInfo *printInfo = [[NSPrintInfo alloc] init]; 
    [printInfo setPrinter:printer]; 

    NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:imageView printInfo:printInfo]; 
    [printOp setShowsPrintPanel:NO]; 
    [printOp runOperation]; 
    //The print job is an empty page :(

    //Pop-up a window just to test the image view 
    NSWindow * window = [[NSWindow alloc] init]; 
    [window makeKeyAndOrderFront:self]; 
    [window setFrame:viewRect display:YES]; 
    [[window contentView] addSubview:imageView]; 
    //The window is sized correctly but empty :(

    [printInfo release]; 
    [imageView release]; 

}

감사합니다!

답변

0

아마도 지금까지 해결했을 것입니다.

  1. 로컬 파일 (네트워크가 아닌)을로드하십시오. 어딘가에 인코딩 문제가있을 수 있으며 NSImage가 파일을 제대로 파싱 할 수 없습니까?

  2. NSImageView 대신 NSImageCell을 사용해보십시오. 이미지 뷰를 잘 작성하지 것처럼 화면에 인쇄에 실패하기 때문에

이 .. 보이는

HTH

관련 문제