0

我正在使用 UIImagePickerViewController 从我的应用程序中的 iPhone 默认相机拍摄照片并将其存储在 Document 目录中。完成这个过程需要很长时间,而且它在 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];
}  
4

1 回答 1

0

当然!

我在我的应用程序中执行以下操作:

  • 将图像存储在后台线程中的图像存储中
  • 创建缩略图(也在后台线程中),将此缩略图存储在核心数据表中;在 ID 类型的字段中

所以我得到了一个流畅的用户界面,用户可以每 2 秒拍一张照片。

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

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

为了您的方便,一些代码:

作为 Imagestore,我使用这些:https ://github.com/snowdon/Homepwner/blob/master/Homepwner/ImageStore.m

-(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!
}
于 2013-01-23T13:46:52.807 回答