Iphone 通过默认相机调整拍摄照片的大小
我正在使用UIImagePickerViewController从我的应用程序中的iPhone默认摄像头拍照,并将其存储在文档目录中。完成这个过程需要很长时间,而且在tableview上显示的速度非常慢。调整图像大小是否有帮助Iphone 通过默认相机调整拍摄照片的大小,iphone,xcode,uiimagepickercontroller,Iphone,Xcode,Uiimagepickercontroller,我正在使用UIImagePickerViewController从我的应用程序中的iPhone默认摄像头拍照,并将其存储在文档目录中。完成这个过程需要很长时间,而且在tableview上显示的速度非常慢。调整图像大小是否有帮助 -(IBAction)takePhoto:(id)sender { if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
-(IBAction)takePhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
}
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];
NSData *imageData = UIImagePNGRepresentation(pickedImage);
NSString *path = [SAVEDIMAGE_DIR stringByAppendingPathComponent:@"image.png"];
[imageData writeToFile:path atomically:YES];
}
当然
我在我的应用程序中执行以下操作:
- 将图像存储在背景线程中的图像存储中
- 创建一个缩略图(也在后台线程中),将该缩略图存储在核心数据表中;在ID类型的字段中
如果您需要其他代码片段,请向Kthanx寻求帮助。当我[通过iphone]向服务器发送捕获的图像时,这需要很长时间。但是其他图像[导入的图像]都很好。是的,这是真的。因此,我将其转换为JPEG格式,并稍微降低了质量:
d=UIImageJPEGRepresentation(图像,0.8)代码>您还可以减小图像的大小。照看ImageHelper
源代码。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self performSelectorInBackground:@selector(saveFoto:) withObject:info];
// you should add some code for indicating the save process
}
// saves the photo in background-thread
-(void)saveFoto:(NSDictionary*)info {
// the following is some stuff that I do in my app - you will probably do some other things
UIImage *image = [ImageHelper normalizeImageRotation: [info objectForKey:UIImagePickerControllerOriginalImage]];
UIImage *thumb = [ImageHelper image:image fitInSize:CGSizeMake(imgWidth, imgWidth) trimmed:YES];
NSString *myGUID = myGUIDCreator();
[[ImageStore defaultImageStore] setImage:image forKey:myGUID];
myCoreDataManagedObject.thumb = thumb;
[self performSelectorOnMainThread:@selector(showYourResultsInTheUI:) withObject:thumb waitUntilDone:NO]; // every UI-Update has to be done in the mainthread!
}