IOS上传图片到七牛 失败了。方法是这样吧?
从相册里选择图片以后 转化成了data数据。然后上传.
回答:
401,token无效,七牛的token是要通过服务端sdk去动态生成,我想楼主已经解决了这个问题。
另外,“裁剪成正方形”,应该指的是:将图片裁剪成长宽一样的正方形,多余部分剪掉,很多app制作头像用得到这个功能。写了个简单demo演示将长方形图片裁剪成正方形,供楼主举一反三:
(void)viewDidLoad {
[super viewDidLoad];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 270, 120)];
_imageView.center = self.view.center;
_image = [UIImage imageNamed:@"Data.png"];
_imageView.image = _image;
[self.view addSubview:_imageView];
UIButton *shapeBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
shapeBtn.frame = CGRectMake(80, _imageView.frame.origin.y + _imageView.frame.size.height +10, 160, 30);
[shapeBtn addTarget:self action:@selector(imgShape:) forControlEvents:UIControlEventTouchDown];
[shapeBtn setTitle:@"图片裁剪" forState:UIControlStateNormal];
[self.view addSubview:shapeBtn];
}
- (void)imgShape:(id)sender {
NSLog(@"裁剪前:image.width:%f, image.height:%f",_image.size.width,_image.size.height);
NSLog(@"===================裁剪图片==========================");
CGRect rect = CGRectMake(0, 0, 120, 120);
CGImageRef cgImg = CGImageCreateWithImageInRect([_image CGImage], rect);
_imageView.frame = CGRectMake(0, 0, 120, 120);
_image = [UIImage imageWithCGImage:cgImg];
_imageView.image = _image;
_imageView.center = self.view.center;
//释放内存
CGImageRelease(cgImg);
NSLog(@"裁剪后:image.width:%f, image.height:%f",_image.size.width,_image.size.height);
}
控制台输出图片裁剪前后的长宽:
裁剪前:
裁剪后:
如果要实现更高级的功能,需要配合图片缩放一起使用。希望我的回答对楼主问题有帮助。
回答:
解决了。谢谢大家。如果进来看到了。顺便教一下我,裁剪成正方形是什么意思吧
以上是 IOS上传图片到七牛 失败了。方法是这样吧? 的全部内容, 来源链接: utcz.com/p/184029.html