【问题标题】:Resize taking photo through default camera通过默认相机调整拍照大小
【发布时间】:2013-01-23 13:39:50
【问题描述】:

我正在使用 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];
}  

【问题讨论】:

    标签: iphone xcode uiimagepickercontroller


    【解决方案1】:

    当然!

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

    • 将图像存储在后台线程中的图像存储中
    • 创建缩略图(也在后台线程中),将此缩略图存储在核心数据表中;在 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!
    }
    

    【讨论】:

    • 如果您需要其他sn-ps,请询问
    • 感谢帮助。当我将捕获的图像 [通过 iphone] 发送到服务器时,它需要很长时间。但其他图像 [导入的图像] 一切正常。
    • 是的,这是真的。因此,我转换为 JPEG 表示并稍微降低质量:d = UIImageJPEGRepresentation(image, 0.8); 您也可以减小图像的大小。照顾ImageHelperSource。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多