user3396127
user3396127

Reputation: 11

retrieving image from rest service in Android

I want to retrieve my images in android from the wcf rest service in order to set them as the markers icons, here is the equivalent code in my iOS application:

NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"images/%@.png", imageName]];

NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath:imagePath]];

UIImage *image = [UIImage imageWithData:data];
marker.icon = image;

Upvotes: 0

Views: 139

Answers (1)

Konstantin Loginov
Konstantin Loginov

Reputation: 16010

There're dozens of different ways, of course.

Personally I'm using library called Picasso. http://square.github.io/picasso/

It also helps with image caching, trimming and literally all sort of image operations you can think of :-)

Usage example:

Picasso.with(context)
    .load(url)
    .placeholder(R.drawable.user_placeholder)
    .error(R.drawable.user_placeholder_error)
    .into(imageView);

It can be also archived with, for example, built-in AsyncTasks, etc. (http://eclipsesource.com/blogs/2012/07/31/loading-caching-and-displaying-images-in-android-part-1/) - but most likely you don't want to do this.

Upvotes: 1

Related Questions