如何在Xamarin IOS中以编程方式在自定义位置保存图像

时间:2017-10-26 09:47:54

标签: c# ios xamarin xamarin.forms uiimage

我需要在我的ipod设备IOS中的不同位置保存图像。默认情况下,它保存在相机胶卷中。我需要保存在其他位置。以下代码是否有效? 如果有人工作,请将其转换为c#

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetChangeRequest *newAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
        newAssetRequest.creationDate = time;
        newAssetRequest.location = location;

        PHObjectPlaceholder *placeholderAsset = newAssetRequest.placeholderForCreatedAsset;

        PHAssetCollectionChangeRequest *addAssetRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:WHICH_ASSET_COLLECTION];
        addAssetRequest addAssets:@[placeholderAsset];

    } completionHandler:^(BOOL success, NSError *error) {
        NSLog(@"Success: %d", success);
    }];

提前致谢

1 个答案:

答案 0 :(得分:0)

您可以使用System.IO.File.WriteAllBytes(String, Byte[])将图像保存到作为参数放置的路径:

File.WriteAllBytes(PATH_TO_LOCATION, byteArray);