Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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 使用UIImagePickerController保存图像_Iphone_Ios5_Uiimage_Uiimagepickercontroller - Fatal编程技术网

Iphone 使用UIImagePickerController保存图像

Iphone 使用UIImagePickerController保存图像,iphone,ios5,uiimage,uiimagepickercontroller,Iphone,Ios5,Uiimage,Uiimagepickercontroller,我正在尝试保存用户使用相机拍摄的图像 1如果我使用UIImageWriteToSavedPhotosAlbum,我似乎无法分配所需的文件名。如何选择文件名? 使用此选项的好处是 [选择器设置源类型:UIImagePickerController源类型PhotoLibrary]; 然后给出了照片库目录的缩略图库 这就引出了我的下一个问题 [选择器设置源类型:UIImagePickerController源类型PhotoLibrary];是否用于从您自己的个人目录获取图像 3在照片库中是否仍然可以通

我正在尝试保存用户使用相机拍摄的图像

1如果我使用UIImageWriteToSavedPhotosAlbum,我似乎无法分配所需的文件名。如何选择文件名? 使用此选项的好处是 [选择器设置源类型:UIImagePickerController源类型PhotoLibrary]; 然后给出了照片库目录的缩略图库

这就引出了我的下一个问题 [选择器设置源类型:UIImagePickerController源类型PhotoLibrary];是否用于从您自己的个人目录获取图像

3在照片库中是否仍然可以通过编程方式创建子文件夹

4最后

正在检查NSPicturesDirectory是否存在,以便我可以对其进行写入 我一直得到一个错误513不允许

提前感谢

1。 要保存您选择的文件名,您需要将图像保存到文档目录。这样做很容易:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo 
{
    NSString *current = [NSString stringWithFormat:@"%@/%@",PHOTODATA_PATH,currentItem];

    UIGraphicsBeginImageContext(CGSizeMake(160,160));
    [image drawInRect:CGRectMake(0,0,160,160)];
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    NSData * thumbSize = UIImageJPEGRepresentation(scaledImage, 1.0);
    [thumbSize writeToFile:[NSString stringWithFormat:@"%@_thumb.jpg",current] atomically:YES];

    NSData * fullSize = UIImageJPEGRepresentation(image, 1.0);
    [fullSize writeToFile:[NSString stringWithFormat:@"%@.jpg",current] atomically:YES];

    [self dismissModalViewControllerAnimated:YES];
}
当然,这段代码可能需要编辑以适合您的具体情况,但提供了使用NSData将照片保存到文件的基本理解和方法

2. 可以,UIImagePickerController资源类型PhotoLibrary将访问设备上的照片库。使用此功能可以访问从相机卷保存或拍摄的任何照片

3. 不,不能使用应用程序在照片库中创建子文件夹。这可以通过使用iPhoto或iTunes等来实现

4.
您只能访问沙盒环境中包含的文档和库路径。将照片保存到照片库的唯一方法是使用适当的公共方法。无需检查目录是否存在,操作系统将负责管理照片库所需的所有后台任务。

您无法为照片库图像指定文件名。ios为保存到照片库中的图像指定一个名为asset url的文件名,我们无法更改

如果需要将图像保存到照片库,可以使用照片库

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
   [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)     [image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
    if (error)
    {
     // Eror
    }
    else
    {
     // Success
    }
   }];
   [library release];
有关更多信息,请查看:


不确定这是否是你所说的子文件夹,但如果你是指具有自定义名称的相册,我使用了这个类别。您需要将图像保存在照片库而不是文档目录中,对吗?如果必须是照片库,则保存在我自己的相册/子目录中。但是我需要从代码中创建相册/子目录。与文件目录相同
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
   [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)     [image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
    if (error)
    {
     // Eror
    }
    else
    {
     // Success
    }
   }];
   [library release];