/// <summary> /// Shares the image at path. /// </summary> /// <param name="_message">Message to share.</param> /// <param name="_imagePath">Path where image exists that needs to be shared.</param> /// <param name="_excludedOptions">List of sharing services to exclude while sharing.</param> /// <param name="_onCompletion">Callback to be triggered when sharing action completes.</param> public void ShareImageAtPath(string _message, string _imagePath, eShareOptions[] _excludedOptions, SharingCompletion _onCompletion) { if (!File.Exists(_imagePath)) { Console.LogWarning(Constants.kDebugTag, "[Sharing] ShareImageAtPath, path is invalid"); ShareImage(_message, null, _excludedOptions, _onCompletion); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, false); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { // Download went wrong if (!string.IsNullOrEmpty(_error)) { Console.LogWarning(Constants.kDebugTag, "[Sharing] ShareImageAtPath, failed to download texture. Error=" + _error); } ShareImage(_message, _texture, _excludedOptions, _onCompletion); }; // Start download _newDownload.StartRequest(); }
protected void PickImageFinished(string _imagePath, ePickImageFinishReason _finishReason) { // Resume unity player this.ResumeUnity(); Console.Log(Constants.kDebugTag, "[MediaLibrary] Finishing pick image, Path=" + _imagePath + " Reason=" + _finishReason); if (OnPickImageFinished != null) { // Failed opertation if (_finishReason != ePickImageFinishReason.SELECTED) { OnPickImageFinished(_finishReason, null); return; } // Download image from given path URL _imagePathURL = URL.FileURLWithPath(_imagePath); DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { if (string.IsNullOrEmpty(_error)) { OnPickImageFinished(ePickImageFinishReason.SELECTED, _texture); } else { Console.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _imagePathURL.URLString); OnPickImageFinished(ePickImageFinishReason.FAILED, null); } }; // Start download _newDownload.StartRequest(); } }
/// <summary> /// Helper for getting Texture from image path. /// </summary> /// <param name="_onCompletion">Callback to be triggered after downloading the image.</param> public void GetImageAsync(DownloadTexture.Completion _onCompletion) { URL _imagePathURL = URL.FileURLWithPath(ImagePath); // Download image from given path DownloadTexture _newDownload = new DownloadTexture(_imagePathURL, true, true); _newDownload.OnCompletion = _onCompletion; // Start download _newDownload.StartRequest(); }
/// <summary> /// Saves an image from the specified url to gallery/media library of the users device. /// \note The path needs to be absolute path if its local file. Take care of the path on multiple platforms as the file structure will be different. /// </summary> /// <param name="_URL">URL to pick the source from. This can be a file url existing on local storage or a web url at remote location.</param> /// <param name="_onCompletion">Callback triggered once save to gallery is done.</param> public void SaveImageToGallery(URL _URL, SaveImageToGalleryCompletion _onCompletion) { // Download texture from given URL DownloadTexture _newDownload = new DownloadTexture(_URL, true, false); _newDownload.OnCompletion = (Texture2D _texture, string _error) => { // Save downloaded texture if (!string.IsNullOrEmpty(_error)) { Console.LogError(Constants.kDebugTag, "[MediaLibrary] Texture download failed, URL=" + _URL.URLString); } // Save image SaveImageToGallery(_texture, _onCompletion); }; // Start download _newDownload.StartRequest(); }