hi, I've got a db on a server and want to get some data fro my iphone. I use TouchJson and everything works fine but I've got a little problem. I don't know how to download images. When I try to build and run the app the emulator just crashes. Got any ideas what to do?
A:
When you get the path to the image from the db you can simply use UIImage
s -imageWithContentsOfFile:
.
flohei
2010-05-10 05:57:21
+2
A:
If your JSON request provides a URL to the image then try:
NSString *path = @"http://sstatic.net/so/img/logo.png";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
Kevin Sylvestre
2010-05-10 06:02:07
+2
A:
Kevin already provided a solution for static images, but if you want to transmit dynamically generated images, you can use the same method with a data: URL.
You'd have to encode your image in Base64 (on the server), then on the client you just have to create a
<img src="data:image/png;base64,the_base64_string_here">
on the client (if using HTML5) or
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:@"data:image/png;base64,the_base64_string_here"]]
(if writing native code).
jcayzac
2010-05-10 06:58:02