ios-上传图片到后台

做第一个项目时,有个版块的个人信息的编辑涉及到头像修改,老大说项目里有通用的代码,让我自己去找。总算找到,搞了许久才弄好,看来理解能力还需要提高啊!!

 1 #pragma mark- 修改头像上传后保存
 2 -(void)uploadMyIco
 3 {
 4     //NSString *fileName = @"myico.jpg";
 5     UIImage *image1 = self.headImageVie.image;    
 6    
 7     NSData *data;
 8     float v = image1.size.width / 240;
 9     CGSize newSize = CGSizeMake(image1.size.width / v, image1.size.height / v);
10     UIGraphicsBeginImageContext(newSize);
11     [image1 drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
12     UIImage *scaleImage  = UIGraphicsGetImageFromCurrentImageContext();
13     UIGraphicsEndImageContext();
14     data = UIImageJPEGRepresentation(scaleImage, 0.8);
15     UIImage *image = [UIImage imageWithData:data];
16     UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil );
17     NSString *fileNamess =[self createImgFileName];
18     NSString* filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileNamess];
19     [data writeToFile:filePath atomically:NO];
20     NSMutableArray *imageArray = [[NSMutableArray alloc]init];
21     [imageArray addObject:[NSDictionary dictionaryWithObject:filePath forKey:@"file"]];
22     self.request = nil;
23     requestType = 2;
24     self.request = [UPRequest uploadPhotoInfo1:@"member/updatePhoto" image:imageArray keyName:@"file" delegate:self params:nil];
25     [SKProgressView ShowHudInView:self.view withTag:2001];
26 }
27 
28 - (NSString *)createImgFileName
29 {
30     static int seedNum = 0;
31     if(seedNum >= 1000)
32         seedNum = 0;
33     seedNum++;
34     
35     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
36     [dateFormatter setDateFormat:@"yyyyMMddHHmmss"];
37     
38     NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
39    // [dateFormatter release];
40     
41     NSString *file = [NSString stringWithFormat:@"temppics%@%03d.jpg", currentDateStr, seedNum];
42     return file;
43 }
View Code

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。