首页 > 代码库 > ios 上传图片base64 demo
ios 上传图片base64 demo
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
//1.获取当前选中相册的照片
UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
//1.1创建一个imageview属性,显示图片,将imageview的(Mode)改成(Aspect Fit)
self.userImage.image = image;
//2.获取图片名字
//注:想要用到以下操作,需要引入以下的内容
//#import <AssetsLibrary/ALAsset.h>
//#import <AssetsLibrary/ALAssetsLibrary.h>
//#import <AssetsLibrary/ALAssetsGroup.h>
//#import <AssetsLibrary/ALAssetRepresentation.h></span>
NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *representation = [myasset defaultRepresentation];
NSString *fileName = [representation filename];
self.imgName = fileName;
SXLog(@"fileName : %@",self.imgName);
//2.1修改头像
[self img_reqest:image imgName:fileName];
};
//2.2
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:imageURL resultBlock:resultblock failureBlock:nil];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)img_reqest:(UIImage *)image imgName:(NSString *)imgName {
//2.1.1 UIImage图片转成Base64字符串:
NSData *data = http://www.mamicode.com/UIImageJPEGRepresentation(image, 1.0f);
NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
//2.3发起请求
}
iOS 图片转成base64编码
http://www.cnblogs.com/ZGSmile/articles/5587226.html
获取透过UIImagePackerController获取的系统相册图片的名称信息及保存系统相册到本地
http://www.myexception.cn/operating-system/1833349.html
ios 上传图片base64 demo