使用UIImagePickerController
时,需要更改裁剪矩形的大小。就我而言,我需要用户选择320x385的图像,但裁剪矩阵当前仅允许320x320(允许编辑时)。如何在使用UIImagePickerController时更改裁剪矩形的大小
任何想法?
使用UIImagePickerController
时,需要更改裁剪矩形的大小。就我而言,我需要用户选择320x385的图像,但裁剪矩阵当前仅允许320x320(允许编辑时)。如何在使用UIImagePickerController时更改裁剪矩形的大小
任何想法?
看一看this blog post,这对于iPhone OS 2.x的提供代码& 3.0
在委托方法的字典返回所有:
NSString *const UIImagePickerControllerMediaType;
NSString *const UIImagePickerControllerOriginalImage;
NSString *const UIImagePickerControllerEditedImage;
NSString *const UIImagePickerControllerCropRect;
NSString *const UIImagePickerControllerMediaURL;
NSString *const UIImagePickerControllerReferenceURL;
NSString *const UIImagePickerControllerMediaMetadata;
我想,你已经使用EditedImage是非常没用的...可能对于一些缩略图...无论如何,info字典包含CropRect数据,唯一需要做的就是重新计算大小并自己裁剪OriginalImage,例如使用下面的代码: UIImage: Resize, then Crop
我没有测试过,这只是理论:) ...但在理论上,这应该工作:d
我做了一个类似的项目。你必须使用图像控制器。在图像控制器上方,您必须添加另一个图像控制器(因为这是您的裁剪区域) aboveImageController的未填充/空白部分是您将采用的位置。 (所以你应该有一个形象与小320x480大小和320x385空在其中。)
UIImage *image=theimageView.image;
CGSize newSize;
newSize.width=320;
newSize.height=385;
UIGraphicsBeginImageContext(newSize);
//x=0 (because widhth : 320) y=0 (aboveImageController's empty part's start)
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef imageRef = CGImageCreateWithImageInRect([newImage CGImage], rect);
UIImage *img = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
您可以使用此
UIImage *image1 = [self resizeImage:image width:320 height:385];
-(UIImage *)resizeImage:(UIImage *)image width:(int)wdth height:(int)hght{
int w = image.size.width;
int h = image.size.height;
CGImageRef imageRef = [image CGImage];
int width, height;
int destWidth = wdth;
int destHeight = hght;
if(w > h){
width = destWidth;
height = h*destWidth/w;
}
else {
height = destHeight;
width = w*destHeight/h;
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmap;
bitmap = CGBitmapContextCreate(NULL, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedFirst);
if (image.imageOrientation == UIImageOrientationLeft) {
CGContextRotateCTM (bitmap, M_PI/2);
CGContextTranslateCTM (bitmap, 0, -height);
} else if (image.imageOrientation == UIImageOrientationRight) {
CGContextRotateCTM (bitmap, -M_PI/2);
CGContextTranslateCTM (bitmap, -width, 0);
}
else if (image.imageOrientation == UIImageOrientationUp) {
} else if (image.imageOrientation == UIImageOrientationDown) {
CGContextTranslateCTM (bitmap, width,height);
CGContextRotateCTM (bitmap, -M_PI);
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
退房GKImagePicker
https://github.com/gekitz/GKImagePicker
示例项目只有iphone和只支持相册,但我很容易扩展到包括ipad和相机。我用它来做一个自定义裁剪视图,它是任何尺寸大小的圆角矩形。
在使用GKImagePicker时,您是如何摆脱原始Apple重拍/使用屏幕的?现在,如果我用相机拍摄照片,首先会显示该屏幕,如果按'使用',那么该屏幕的GKImagePicker裁剪版本会立即显示。我只想要GKImagePicker屏幕。 – Ramsel 2013-09-23 21:46:40
@RobertWagstaff,你是如何得到GKImagePicker使用相机的?你仍然可以用相同的方法设置作物长度,或者你只是在原始代码没有的情况下实现自己的相机方法吗? – DelightedD0D 2014-05-17 09:49:14
@ DelightedD0D是的,我实现了我自己的相机方法 – 2014-05-21 18:35:25
这篇文章doesen't帮助。这是关于根据iOS 4.x中修复的内置裁剪和缩放视图中的默认方形矩形不能正确裁剪返回的图像。我相信这个问题是关于改变预览/裁剪功能的纵横比的可能性。 Anybodu有幸运? – esbenr 2011-09-01 07:17:46