-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *newImage = [info valueForKey:UIImagePickerControllerEditedImage];
if(!newImage)
newImage = [info valueForKey:UIImagePickerControllerOriginalImage];
inserImage = newImage;
CGFloat width = inserImage.size.width;
CGFloat height = inserImage.size.height;
NSLog(@"inserImage.size.width:%f inserImage.size.height:%f",inserImage.size.width,inserImage.size.height);
//定义缩略图的大小 #define IMAGE_W 72 #define IMAGE_H 98
CGFloat lValue = width/height;
//300/250
if (lValue > 1.4f) {
if (width > 280.0f) {
width = 280;
height = roundf(width/lValue);
}
}
else {
if (height > 200) {
height = 200;
width = roundf(height*lValue);
}
}
// NSData *imageDatas = UIImagePNGRepresentation(inserImage);
// NSLog(@"imageDatas:%@",[imageDatas description]);
// NSString *aString = [[NSString alloc] initWithData:imageDatas encoding:NSUTF8StringEncoding];
// NSLog(@"aString:%@",aString);
// NSString *base64 = [[aString dataUsingEncoding:NSUTF8StringEncoding] base64Encoded];
NSData *imagedata=[NSData dataWithData:UIImagePNGRepresentation(inserImage)];
NSString *base64string=[imagedata base64Encoding];
NSString *uuids = [self getUuid];
[[BCAppDelegate sharedInstance].USERINFO setSaveAvataPath:uuids];
[self saveImage:inserImage imane:uuids];
if (_delegate && [_delegate respondsToSelector:@selector(myInformationUpdate)]) {
[_delegate myInformationUpdate];
}
[self uploadAvatar:base64string];
[self dismissModalViewControllerAnimated:YES];
}```
NSString *base64string=[imagedata base64Encoding];
把NSData 类型直接转换成base64 字符串上传 头像一般这么做