在我的iPhone应用程序中,我用相机拍照,然后我想将其调整为290*390像素.我正在使用此方法调整图像大小:
UIImage *newImage = [image _imageScaledToSize:CGSizeMake(290, 390)
interpolationQuality:1];
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但它是一个未记录的功能,所以我不能再使用iPhone OS4了.
那么...调整UIImage大小的最简单方法是什么?
我目前正在iOS上使用Imgur将图像上传到服务器,代码如下:
NSData* imageData = UIImagePNGRepresentation(image);
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* fullPathToFile = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"SBTempImage.png"];
[imageData writeToFile:fullPathToFile atomically:NO];
[uploadRequest setFile:fullPathToFile forKey:@"image"];
Run Code Online (Sandbox Code Playgroud)
代码在模拟器中运行并从模拟器的照片库上传文件时工作正常,因为我在快速以太网连接上.但是,在选择使用iPhone拍摄的图像时,相同的代码会在iPhone上超时.所以,我尝试通过从网络上保存一个小图像并试图上传它,这是有效的.
这让我相信iPhone拍摄的大图像会在有点慢的3G网络上超时.有没有办法在发送之前压缩/调整iPhone的图像大小?
谢谢!
所以我一直试图弄清楚我现在做错了一段时间,我无法弄明白.我想要完成的是:
UIImagePickerControllerUIButton出于某种原因,每次我拍摄照片时都会在照片内失真UIButton,看起来好像裁剪不能正常工作.这就是我的工作.在didFinishPickingMediaWithInfo方法中我有以下代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Copy the image to the userImage variable
[picker dismissModalViewControllerAnimated:YES];
userImage = nil;
//Rotate & resize image
userImage = [self resizeAndRotatePhoto:(UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage]];
NSLog(@"Userimage size, width: %f , height: %f", userImage.size.width , userImage.size.height);
//Update the image form field with the image and set the image in the controller
NSLog(@"Button size is height: %f , width: %f" , userImageAvatarButton.frame.size.height , userImageAvatarButton.frame.size.width);
[userImageAvatarButton.layer setMasksToBounds:YES];
[userImageAvatarButton.layer setCornerRadius:3.0]; …Run Code Online (Sandbox Code Playgroud) ios ×3
ios4 ×2
uiimage ×2
cocoa-touch ×1
file-upload ×1
ios5 ×1
nsdata ×1
objective-c ×1
resize ×1