TTPhotoViewController - pre-load imagines in background?

59 views
Skip to first unread message

Bill

unread,
Apr 10, 2010, 10:35:50 AM4/10/10
to Three20
Is there any way to make the TTPhotoViewController load pictures in
the background? I've gotten a couple complaints that when viewing
picture galleries that it takes too long for the high resolution
pictures to load.

When you launch the gallery you're presented with the thumbnail then
after a couple of seconds the image changes to the higher resolution
image. Is there a way to continue loading pictures in the background
so when someone flips to the next picture it's clear right away?

Many Thanx!

AhmadTK

unread,
Jan 17, 2012, 2:58:06 AM1/17/12
to thr...@googlegroups.com
hello Bill have you found any solution for this?

Yoshi Sugawara

unread,
Jan 17, 2012, 5:39:05 AM1/17/12
to thr...@googlegroups.com, thr...@googlegroups.com
This is actually quite simple - in the photo view controller, maybe in viewWillAppear, make a TTURLRequest to the upcoming photos in the photo source. 

You might need to adjust the image cache size in TTURLCache to cache larger size images. 

I don't have a code example since I'm on my iPhone but the gist of it is you exploit the image caching to preload the images. I have this working on my app. 

Yoshi

Sent from my iPhone

On Jan 16, 2012, at 9:58 PM, AhmadTK <kayyal...@gmail.com> wrote:

hello Bill have you found any solution for this?

--
To learn more about Three20, check out http://three20.info
 
You received this message because you are subscribed to the Google
Groups "Three20" group.
To post to this group, send email to thr...@googlegroups.com
To unsubscribe from this group, send email to
three20+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/three20?hl=en

Yoshi Sugawara

unread,
Jan 17, 2012, 3:17:07 PM1/17/12
to thr...@googlegroups.com
Here's a code sample:

I subclassed TTPhotoViewController, and overrode the updateChrome method:

-(void) preFetchNextImages:(NSInteger)count {
for (int i = 1; i<=count; i++) {
NSInteger nextIndex = self.centerPhotoIndex + i;
if ( nextIndex >= [[self photoSource] numberOfPhotos] ) {
// we're at the end, stop
return;
}
[self preFetchImageAtIndex:nextIndex];
}
}

-(void) preFetchImageAtIndex:(NSInteger)index {
id<TTPhoto> nextPhoto = [[self photoSource] photoAtIndex:index];
TTDINFO(@"prefetching photo at index: %d file:
%@",index,[nextPhoto URLForVersion:TTPhotoVersionLarge]);
TTURLRequest *request = [TTURLRequest requestWithURL:[nextPhoto
URLForVersion:TTPhotoVersionLarge] delegate:self];
request.response = [[[TTURLImageResponse alloc] init] autorelease];
[request send];
}

- (void)updateChrome {
[super updateChrome];
TTDINFO(@"update chrome called: prefetching next image");
NSInteger numberOfImagesToPrefetch = 5;
[self preFetchNextImages:numberOfImagesToPrefetch];
// just for my debug purposes
[[TTURLCache sharedCache] logMemoryUsage];
}

I locally modified TTURLCache to adjust the kLargeImageSize constant
to cache larger images:
static const CGFloat kLargeImageSize = 2048 * 2048;

There are better ways to do the above override but alas, I am lazy :)

Hope that helps,
Yoshi

Ahmad Kayyali

unread,
Jan 18, 2012, 2:27:45 AM1/18/12
to thr...@googlegroups.com
Thank you Yoshi I am going to try that right now.
Reply all
Reply to author
Forward
0 new messages