I'm developing a photography software in Xamarin.iOS. I'm using the PHPhoto class.
When I take a photo, I'm trying to send it to the web. I plan to send them in byte[]. Where can I get the data for the photo in the DidFinishCapture method? When I start the debug launch, I see that PHPhotoLibrary.SharedPhotoLibrary.PerformChanges() will automatically save the photos to the photo library.
How do I retrieve photos by byte[]? I couldn't find it in PhotoData.
I thought there was a path for the saved photos in LivePhotoCompanionMovieUrl, but this is always null.
public partial class PhotoCaptureDelegate : AVCapturePhotoCaptureDelegate
{
public override void DidFinishCapture(AVCapturePhotoOutput captureOutput,
AVCaptureResolvedPhotoSettings resolvedSettings,
NSError error)
{
PHPhotoLibrary.RequestAuthorization(status =>
{
if (status == PHAuthorizationStatus.Authorized)
{
PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() =>
{
var creationRequest = PHAssetCreationRequest.CreationRequestForAsset();
creationRequest.AddResource(PHAssetResourceType.Photo, PhotoData, null);
var url = LivePhotoCompanionMovieUrl;
if (url != null)
{
var livePhotoCompanionMovieFileResourceOptions = new PAssetResourceCreationOptions
{
ShouldMoveFile = true
};
creationRequest.AddResource(PHAssetResourceType.PairedVideo, url, livePhotoCompanionMovieFileResourceOptions);
}
}, (success, err) =>
{
if (err != null)
Debug.WriteLine($"Error occurered while saving photo to photo library: {error.LocalizedDescription}");
});
}
});
}
}
}
If you want to convert the photo to Byte array , you could use the plugin Media.Plugin from Nuget to pick or take photo .
Then convert it to Stream firstly before convert it to byte array .
Now you can get the byte array like following
Update
You could use UIImagePickerController
And invoke the following lines when need to take photo
Now you can get the byte array like following