做第一个项目时,有个版块的个人信息的编辑涉及到头像修改,老大说项目里有通用的代码,让我自己去找。总算找到,搞了许久才弄好,看来理解能力还需要提高啊!!
#pragma mark- 修改头像上传后保存
-(void)uploadMyIco
{
//NSString *fileName = @"myico.jpg";
UIImage *image1 = self.headImageVie.image; NSData *data;
float v = image1.size.width / ;
CGSize newSize = CGSizeMake(image1.size.width / v, image1.size.height / v);
UIGraphicsBeginImageContext(newSize);
[image1 drawInRect:CGRectMake(, , newSize.width, newSize.height)];
UIImage *scaleImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
data = UIImageJPEGRepresentation(scaleImage, 0.8);
UIImage *image = [UIImage imageWithData:data];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil );
NSString *fileNamess =[self createImgFileName];
NSString* filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileNamess];
[data writeToFile:filePath atomically:NO];
NSMutableArray *imageArray = [[NSMutableArray alloc]init];
[imageArray addObject:[NSDictionary dictionaryWithObject:filePath forKey:@"file"]];
self.request = nil;
requestType = ;
self.request = [UPRequest uploadPhotoInfo1:@"member/updatePhoto" image:imageArray keyName:@"file" delegate:self params:nil];
[SKProgressView ShowHudInView:self.view withTag:];
} - (NSString *)createImgFileName
{
static int seedNum = ;
if(seedNum >= )
seedNum = ;
seedNum++; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
// [dateFormatter release]; NSString *file = [NSString stringWithFormat:@"temppics%@%03d.jpg", currentDateStr, seedNum];
return file;
}
部门logo修改是是参照写的〜
#pragma mark- 图像上传保存
- (void)uploadDepartmentLogo//上传部门logo图片
{
NSString *fileName = @"departMentLogo.jpg";
UIImage *image1 = self.headImageView.image;
NSData *data;
if ( UIImagePNGRepresentation(image1) == nil )
{
data = UIImageJPEGRepresentation(image1, );
fileName = @"departMentLogo.png";
} else {
data = UIImagePNGRepresentation(image1);
fileName = @"departMentLogo.jpg";
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:fileName];
[data writeToFile:fullPathToFile atomically:NO]; NSMutableArray *array = [NSMutableArray arrayWithCapacity:];
[array addObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:] forKey:@"type"]];
[array addObject:[NSDictionary dictionaryWithObject:self.deptId forKey:@"deptId"]]; NSMutableArray *imageArray = [[NSMutableArray alloc]init];
[imageArray addObject:[NSDictionary dictionaryWithObject:fullPathToFile forKey:@"file"]];//deptHead self.request = nil;
requestType = ;
self.request = [UPRequest uploadPhotoInfo1:@"dept/uploadPhoto" image:imageArray keyName:@"file" delegate:self params:array];
}