Loading Remote Images

Loading remote images

Here's a method that I actually used in an application and I know it works:

try {
URL thumb_u = new URL("http://www.example.com/image.jpg");
Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
myImageView.setImageDrawable(thumb_d);
}
catch (Exception e) {
// handle it
}

I have no idea what the second parameter to Drawable.createFromStream is, but passing "src" seems to work. If anyone knows, please shed some light, as the docs don't really say anything about it.

Android Loading remote images

You could also try this out if you need to cache those images in your app.

Loopj Image Cache

Loading remote image into Tableview cell

Here's what the apple docs has to say about layoutSubviews:

Subclasses can override this method as needed to perform more precise
layout of their subviews. You should override this method only if the
autoresizing and constraint-based behaviors of the subviews do not
offer the behavior you want.

Since loading an image has nothing to do with autoresizing or adjusting constraints, you'd be misusing the method. Additionally, layoutSubviews is often times called more than once for a visible view (such as when you rotate the device). You don't need to load the image more than once.

cellForRowAt is the appropriate method for downloading the image you need to configure the cell.

Loading Remote images in TableView while keeping sizes intact

You need to get the image height and width dynamically first and set the same hieght and width to your table view cells.

I have not added table view but just some code will help you see how you can show two different images with their original height and width and adding the same to a view.

 NSURL *imageURL1 = [NSURL URLWithString:@"http://cdn.macrumors.com/article-new/2014/12/applelogo.png"];
NSData *imageData1 = [NSData dataWithContentsOfURL:imageURL1];
UIImage *image1 = [UIImage imageWithData:imageData1];

UIImageView *imageView1 = [[UIImageView alloc] initWithImage: image1];
//CGFloat height = imageView.frame.size.height;
//CGFloat width = imageView.frame.size.width;
[self.view addSubview:imageView1];

//sample urls :- http://pre01.deviantart.net/e711/th/pre/f/2013/179/2/c/ios_7_icons__updated__by_iynque-d69mme1.png

NSURL *imageURL2 = [NSURL URLWithString:@"http://icons.iconarchive.com/icons/position-relative/social-2/128/ios-icon.png"];
NSData *imageData2 = [NSData dataWithContentsOfURL:imageURL2];
UIImage *image2 = [UIImage imageWithData:imageData2];

UIImageView *imageView2 = [[UIImageView alloc] initWithImage: image2];
CGFloat height = imageView2.frame.size.height;
CGFloat width = imageView2.frame.size.width;
imageView2.frame = CGRectMake(0, 300, width, height);
NSLog(@"height :- %f, Width :- %f ",height, width);

[self.view addSubview:imageView2];

How to load remote images using Titanium Alloy

The following code works fine for me with 4.0.0.GA and 4.1.0.GA:

var win = Ti.UI.createWindow({
backgroundColor: 'green'
});

var userImage = Ti.UI.createImageView({
id: "userImage",
image: "http://graphics.ucsd.edu/~henrik/images/imgs/face_bssrdf.jpg",
width: 90,
center: 0,
height: 90,
});

win.add(userImage);

win.open();

screenshot



Related Topics



Leave a reply



Submit