Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 通过默认相机调整拍摄照片的大小_Iphone_Xcode_Uiimagepickercontroller - Fatal编程技术网

Iphone 通过默认相机调整拍摄照片的大小

Iphone 通过默认相机调整拍摄照片的大小,iphone,xcode,uiimagepickercontroller,Iphone,Xcode,Uiimagepickercontroller,我正在使用UIImagePickerViewController从我的应用程序中的iPhone默认摄像头拍照,并将其存储在文档目录中。完成这个过程需要很长时间,而且在tableview上显示的速度非常慢。调整图像大小是否有帮助 -(IBAction)takePhoto:(id)sender { if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])

我正在使用UIImagePickerViewController从我的应用程序中的iPhone默认摄像头拍照,并将其存储在文档目录中。完成这个过程需要很长时间,而且在tableview上显示的速度非常慢。调整图像大小是否有帮助

-(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类型的字段中
所以我得到了一个平滑的用户界面,用户可以每2秒拍一张照片

表视图的平滑度也没有问题。虽然我也从后台线程填充TableViewCells ImageView(当然,在后台准备图像,在主线程中分配给UIImageView)

我希望这对你有帮助。欢迎进一步提问

为方便起见,提供了一些代码:

作为Imagestore,我使用这些:


如果您需要其他代码片段,请向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!
}