#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //編碼圖片 NSString *password = @"http://172.16.3.237/broadcast/./uploads//20160118190424975_115.png"; NSURL *url = [NSURL URLWithString: password]; NSData *data = [NSData dataWithContentsOfURL:url]; //轉換格式 data->image UIImage *image = [UIImage imageWithData:data]; //轉換格式 image->data NSData *passwordData = UIImageJPEGRepresentation(image, 1); NSString *result = [passwordData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]; NSLog(@"%@", result); //解碼圖片 NSData *decodeData = [[NSData alloc]initWithBase64EncodedString:result options:0]; // NSString *decodeStr = [[NSString alloc]initWithData:decodeData encoding:NSASCIIStringEncoding]; //轉換格式 data->image UIImage *image1 = [UIImage imageWithData:decodeData]; //將圖片顯示在視圖上 UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 375, 400)]; imageView.image = image1; [self.view addSubview:imageView]; }