• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Image from WebView is sometimes blank
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image from WebView is sometimes blank


  • Subject: Re: Image from WebView is sometimes blank
  • From: Duncan Oliver <email@hidden>
  • Date: Thu, 20 May 2010 14:20:57 -0500

Thanks. I added the layout line, and that seems to have fixed it. I'll
have to do some more testing, but so far, I haven't had the problem
anymore.
---
Duncan Oliver
email@hidden

On Fri, May 14, 2010 at 1:27 PM, Adam R. Maxwell <email@hidden> wrote:
>
> On May 11, 2010, at 2:33 PM, Duncan Oliver wrote:
>
>> I have a WebView that I use to capture a thumbnail of a loaded webpage
>> using cacheDisplayInRect:. The WebView object is created
>> programmatically and not attached to a window. About half the time,
>> the image it grabs is blank. I can't seem to figure out if I'm trying
>> to grab it too soon or what. Would love to know how to get a completed
>> image all the time. Thanks in advance.
>
> This can be kind of tricky, especially when you need to make it work for arbitrary pages; just figuring out when the webview finishes loading is tricky, since -[WebView isLoading] doesn't account for redirection.
>
>>
>> Here's the code:
>>
>> - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
>> {
>>       if ([frame isEqualTo:[sender mainFrame]])
>>       {
>
> My first guess is that pages aren't fully loaded when you get this callback, but that's generally only a problem with redirects.
>
>>               if ([sender saveThumbnail] == YES)
>>               {
>>                       NSView *mainFrameView = sender.mainFrame.frameView;
>>                       NSBitmapImageRep *thumbnailImageRep = [mainFrameView
>> bitmapImageRepForCachingDisplayInRect:[mainFrameView frame]];
>>                       [sender cacheDisplayInRect:[mainFrameView frame]
>>                                         toBitmapImageRep:thumbnailImageRep];
>
> Another potential problem is that you need to force layout in the WebDocumentView; this shouldn't be necessary, but I couldn't find any other workaround.  Try sending
>
> [[mainFrameView documentView] layout];
>
> before calling -cacheDisplayInRect:toBitmapImageRep:.  This fixed a bunch of random white page issues for me.  If you use -[WebFrameView setAllowsScrolling:NO] at some point, the problem is much worse (as of Safari 4.0.3).
>
> I have a BSD-licensed web thumbnail class here:
>
> http://code.google.com/p/fileview/source/browse/trunk/fileview/FVWebViewIcon.m
>
> It's complicated by threading issues, but shows one way to track redirected frames during loading, and also how to draw.
>
> hth,
> Adam
>
>
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Image from WebView is sometimes blank (From: Duncan Oliver <email@hidden>)
 >Re: Image from WebView is sometimes blank (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: How does NSSavePanel support UTIs?
  • Next by Date: Listening for token deletion in NSTokenField
  • Previous by thread: Re: Image from WebView is sometimes blank
  • Next by thread: Re: Archiving NSBlockPredicate and NSPredicate date functions
  • Index(es):
    • Date
    • Thread