我正在尝试接收网址图片并将图片发布为base64格式。
我这样解决但我找不到任何解决方案。
我的.h文件
@interface urlconnection : NSObject
{
id delegate;
NSMutableData *receivedData;
NSURL *url;
// NSData * imageData;
IBOutlet NSImageView * myimages;
//and also trying UIImageView also atleast i didn't receive the image
}
@property (nonatomic,retain) NSMutableData *receivedData;
@property (retain) id delegate;
- (void)post: (NSString *)urlString;
@end
我的实施文件是
- (void)post: (NSString *)urlString {
myimages.image = [NSImageView imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://www.iphonedevelopers.com/files/2010/03/iphone-sdk2.jpg" ]]];
NSLog(@"image shown successfully");
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:
[NSURL URLWithString:@"http://www.iphonedevelopers.com/files/2010/03/iphone-sdk2.jpg"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"image/"
forHTTPHeaderField:@"Content-type"];
[request setValue:[NSString stringWithFormat:@"%d", imageData length]]
forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:imageData];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
请朋友帮助我,因为我是新概念
请建议这个概念的最佳教程......
答案 0 :(得分:2)
要发布图片,您需要一个能够在服务器端接收图片的正确服务器网络服务。
试试此链接可以帮助您upload your image from application
我认为使用异步文件下载图像将是下载图像的正确方法,因为您的代码将冻结应用程序,直到您的图像下载。
您可以试试这个link.可能会有更好的下载示例。
答案 1 :(得分:1)
myimages.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL
URLWithString:@"http://www.iphonedevelopers.com/files/2010/03/iphone-sdk2.jpg" ]]];
答案 2 :(得分:1)
从网址获取图片:
yourImageView.image= [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:stringContainningURL]]];