/// <summary> /// Gets an Image from the Gallery using the NativeGallery Plugin /// </summary> public void PickImage() { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } var newTexture = DuplicateTexture(texture); Sprite mySprite = Sprite.Create(newTexture, new Rect(0.0f, 0.0f, newTexture.width, newTexture.height), new Vector2(0f, 0f), 100.0f); SourceImage.sprite = mySprite; } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); ResizeSourceSprite(); }
public void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } Texture2D readableText = new Texture2D(texture.width, texture.height); readableText = duplicateTexture(texture); // readableText.LoadImage(texture.GetRawTextureData()); Debug.Log(readableText.isReadable); resizeImage.SetTexture(readableText); SaveImageFromGallery(readableText); InstantiateImage(readableText); } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); }
private void PickImage() { isProcessing = true; NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = new Texture2D(2, 2); texture.LoadImage(File.ReadAllBytes(path)); // Assign texture to a temporary cube and destroy it after 5 seconds GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 10f; cube.transform.forward = -Camera.main.transform.forward; cube.GetComponent <Renderer>().material.mainTexture = texture; Destroy(cube, 5f); // If a procedural texture is not destroyed manually, // it will only be freed after a scene change Destroy(texture, 5f); } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); isProcessing = false; }
public void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image var tempPic = NativeGallery.LoadImageAtPath(path, maxSize); if (tempPic == null) { Debug.Log("Couldn't load texture from " + path); return; } _memorizePhotos.newPath = path; _memorizePhotos.beginArrayAdd = true; _memorizePhotos.thumbnailList.Add(tempPic); _memorizePhotos.thumbnailIteration++; SetCurrentImage(path, tempPic, true); } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); }
private void PickImage() { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { if (path != null) { Texture2D texture = NativeGallery.LoadImageAtPath(path); if (texture == null) { Debug.LogError("Não encontrou a imagem em: " + path); return; } float width = texture.width; float height = texture.height; if (width != 2 * height) { Debug.LogError("Imagem está com dimensões inadequadas"); return; } sprite = Sprite.Create(texture, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f)); controller.SpawnItem("Exemplo", sprite); } }, "Selecionar imagem 360"); }
private void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image _imgTexture = NativeGallery.LoadImageAtPath(path, maxSize); if (_imgTexture == null) { Debug.Log("Couldn't load texture from " + path); return; } if (!_material.shader.isSupported) // happens when Standard shader is not included in the build { _material.shader = Shader.Find("Legacy Shaders/Diffuse"); } _material.mainTexture = _imgTexture; } }, "Selecione uma imagem", "image/*"); Debug.Log("Permission result: " + permission); }
//NativeGallery 에셋-> https://github.com/yasirkula/UnityNativeGallery 지침활용 private void PickImage(int maxSize) { //안드로이드 갤러리접근 NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // 선택된 이미지의 Texture 생성 Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } //texture를 byte로 변환 texture = duplicateTexture(texture); bytes = texture.EncodeToPNG(); Debug.Log("GallyPickup " + bytes[0]); Destroy(texture, 5f); socket.instance.ImageServer_G(); } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); }
public void PickImage(int maxSize) //이미지를 가져오는 함수 { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } Sprite sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100f); profileImage.sprite = sprite; StartCoroutine(SaveImage(texture)); } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); if (permission == NativeGallery.Permission.Denied) { NativeGallery.OpenSettings(); } }
private void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { //Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } Sprite sp = Sprite.Create(texture, new Rect(Vector2.zero, new Vector2(texture.width, texture.height)), Vector2.zero); GameObject ui = UIController.Instance.Push("PhotoSetting"); ui.GetComponentInChildren <PhotoSetting>().Init(sp); // Assign texture to a temporary quad and destroy it after 5 seconds // If a procedural texture is not destroyed manually, // it will only be freed after a scene change //Destroy(texture, 5f); } }, "Select a PNG image", "image/png", maxSize); Debug.Log("Permission result: " + permission); }
//Carica Texture all'interno del Prefab PictureImage utilizzato come quadro private void LoadImageInsidePicture() { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, IMG_MAXSIZE); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } foreach (GameObject element in GameObject.FindGameObjectsWithTag("TakePictureBtn")) { element.SetActive(false); } EnableButtonPhoto(); pictureGO = Instantiate(Resources.Load <GameObject>("Prefabs/Picture/PictureImage")); pictureGO.GetComponent <PictureController>().SetMediaPath(path); Util.ResizeScalePictureToPoint(pictureGO, texture); pictureGO.GetComponent <Renderer>().material.mainTexture = (Texture)texture; confirmSavePhotoBtn.GetComponent <SavePhotoController>().setPicture(pictureGO); confirmCancelPhotoBtn.GetComponent <SavePhotoController>().setPicture(pictureGO); } }, "Select a image", "image/*", IMG_MAXSIZE); Debug.Log("Permission result: " + permission); }
public void OpenExplorer(int maxSize) { this.detector.GetComponent <scrDetector>().mode = 1; NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); //Texture2D texture = new Texture2D(aux.width, aux.height); //texture.SetPixels(aux.GetPixels()); //texture.Apply(); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } // Assign texture to a temporary quad and destroy it after 5 seconds this.image.texture = texture; this.detector.GetComponent <scrDetector>().boxFactory.GetComponent <scrBoxFactory>().DestroyBoxes(); } }, "Select a PNG image", "image/png"); Debug.Log("Permission result: " + permission); }
private IEnumerator TakeScreenshotAndSave() { NativeGallery.Permission permission = NativeGallery.CheckPermission(); if (permission == NativeGallery.Permission.ShouldAsk) { permission = NativeGallery.RequestPermission(); } else { } takingScreenshot = true; yield return(new WaitForEndOfFrame()); Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); ss.Apply(); fotos = Random.Range(10000, 99999); // Save the screenshot to Gallery/Photos string name = string.Format("foto_" + fotos + ".png", Application.productName, "{0}", System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); //Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name)); takingScreenshot = false; string stringX = "Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name); //textorefleja.text+=stringX; todo.SetActive(true); camaraimage.sprite = camarasprite; }
//选择一个png图片 private void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image Path:" + path); if (path != null) { Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture form: " + path); return; } GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad); quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f; quad.transform.forward = Camera.main.transform.forward; quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f); Material material = quad.GetComponent <Renderer>().material; if (!material.shader.isSupported) { material.shader = Shader.Find("Legacy Shaders/Diffuse"); } material.mainTexture = texture; Destroy(quad, 5f); Destroy(texture, 5f); } }, "Select a PNG image", "image/png", maxSize); Debug.Log("Permisson result :" + permission); }
/// <summary> /// Select the image and process the request /// </summary> /// <param name="campaignName">name of the campaign</param> private void PickImage(string campaignName) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D tex = NativeGallery.LoadImageAtPath(path, 4096); if (tex == null) { Debug.Log("Couldn't load texture from " + path); return; } tex.Apply(); var v = new Texture2D(2, 2); v.LoadImage(tex.EncodeToPNG(), false); v.Apply(); ///map.sprite = Sprite.Create(v, new Rect(0.0f, 0.0f, v.width, v.height), new Vector2(0.5f, 0.5f), 100.0f); SharedImageData sid = new SharedImageData(); sid.bytes = v.EncodeToPNG(); sid.info = null; string finalPath = SerializationManager.CreatePath(campaignName + "/NewMap.map"); SerializationManager.SaveObject(finalPath, sid); } }, "Select a PNG image", "image/png", 4096); Debug.Log("Permission result: " + permission); }
public void OnClickUploadImageButton() { //NativeGallery.PermisionType permisionType = new NativeGallery.PermissionType(); NativeGallery.Permission per = NativeGallery.RequestPermission(new NativeGallery.PermissionType()); // probably should do some permissions checking here NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, 2073600, false); if (texture == null) { return; } //StartCoroutine(UploadImage(texture)); UploadImage(texture); } }, "Select an image", "image/*"); }
public void PickImage(int maxSize = 10000) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } Sprite sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(.5f, .5f), 100f); if (sprite == null) { Debug.Log("Error creating sprite"); } imagenJugador.sprite = sprite; pathImagenJugador = path; } }, "Seleccionar imagen", "image/*"); Debug.Log("Permission result: " + permission); }
private void PickImage(int maxSize) { var AM = AppManager.Instance; NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { this._path = path; Debug.Log("_path111 " + _path); if (AM.openNoteMedia) { AppManager.Instance._noteMediaPaths.Add(path); } else { AppManager.Instance._mediaPaths.Add(path); } // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); AddFile(); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } //Destroy(texture, 5f); } }, "Выберите изображения для объявления", "image/png", maxSize); Debug.Log("Permission result: " + permission); }
/// <summary> /// 打开相册 选择多张照片 /// </summary> public static void OpenPhotos(Action <Texture2D[]> callBack) { NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((string[] path) => { if (path == null || path.Length == 0) { return; } Texture2D[] texs = new Texture2D[path.Length]; for (int i = 0; i < path.Length; i++) { try { if (!string.IsNullOrEmpty(path[i])) { texs[i] = NativeGallery.LoadImageAtPath(path[i]); } } catch (Exception ex) { Debug.LogWarning("第" + i + "张图片处理失败 : " + ex.Message + "\n" + path[i]); } } if (callBack != null) { callBack(texs); } }); if (permission != NativeGallery.Permission.Granted) { ShowToast("当前没有相册访问权限,请在设置中打开"); //打开应用程序设置 if (NativeGallery.CanOpenSettings()) { NativeGallery.OpenSettings(); } } }
private void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); m_LocalFileName = path.ToString(); int te = UnityEngine.Random.Range(11111, 9999999); imageId = te.ToString(); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } /* * // Assign texture to a temporary quad and destroy it after 5 seconds * GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad); * quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f; * quad.transform.forward = Camera.main.transform.forward; * quad.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f); * * * * //Rect rec = new Rect(0, 0, texture.width, texture.height); * //ProfilePic.GetComponent<Image>().sprite = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100); * * * Material material = quad.GetComponent<Renderer>().material; * if (!material.shader.isSupported) // happens when Standard shader is not included in the build * material.shader = Shader.Find("Legacy Shaders/Diffuse"); * * material.mainTexture = texture; */ ScreenShotGO.SetActive(true); Rect rec = new Rect(0, 0, texture.width, texture.height); float rangecreator = texture.height / (float)texture.width; ScreenShotGO.transform.Find("Image").transform.GetComponent <Image>().rectTransform.localScale = new Vector3(1f, rangecreator, 1f); ScreenShotGO.transform.Find("Image").transform.GetComponent <Image>().sprite = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100); ResultText.text += texture.height.ToString(); StartCoroutine(TakeScreenShot(ScreenShotGO, texture)); //CanvasGO.SetActive(false); //StartCoroutine(TakeScreenShot(CanvasGO, quad, texture)); //Destroy(quad, 10f); //UploadImage(texture); } }, "Select a PNG image", "image/png", maxSize); //Debug.Log("Permission result: " + permission); }
public void TakePhoto(int maxSize = -1) { //调用插件自带接口,拉取相册,内部有区分平台 NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { { // 此Action为选取图片后的回调,返回一个Texture2D Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { { Debug.Log("Couldn't load texture from " + path); return; } } Debug.Log(texture.name); head.texture = texture; //将选择的图片对我们的RawImage进行赋值 Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); img.sprite = sprite; // img.tex = head.texture; } } }, "选择图片", "image/png", maxSize); }
void PickImage(int maxSize) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } // turn texture to sprite Sprite sprite = Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(.5f, .5f), 100f); Debug.Log("sprite created"); // attach it to the button sprite characterImage.sprite = sprite; } }, "Select an image", "image/"); Debug.Log("Permission result: " + permission); }
private static void CheckPermission(NativeGallery.Permission permission) { if (permission != NativeGallery.Permission.Granted) { DialogGUI.ShowMessageDialog(GUIManager.guiGameObject, "Please grant N-Space permission to access your photo gallery."); } }
/// <summary> /// opens file choosing dialog /// </summary> public static string PickImage(int maxSize) { string result = null; NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { result = path; }, "Select a PNG image", "image/*", maxSize); return(result); }
//saves an image to be used in a flashcard private string saveImage() { string newPath = ""; NativeGallery.Permission permission = NativeGallery.SaveImageToGallery(imageToSave, "GalleryTest", "Image.png", (success, path) => newPath = path ); return(newPath); }
private void PickImage(NativeAction actionPick) { #if UNITY_ANDROID NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGalleryForAndroid((path) => { if (path.IsNotNullAndEmpty()) { mPhotoPath = path; ImageDownloadUtils.Instance.SetAsyncImage("file://" + path, ImgPhoto); BtnDel.gameObject.SetActive(true); } Debug.Log("Image path: " + path); }, "选择图片", "image/*", false, action); } }, (int)actionPick); #elif UNITY_IOS // NativeGallery.Permission rest; if (actionPick == NativeAction.Album) { NativeGallery.Permission rest = NativeGallery.RequestIPhonePermission(1); if (rest == NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGallery((backPath) => { if (backPath.IsNotNullAndEmpty()) { mPhotoPath = backPath; ImageDownloadUtils.Instance.SetAsyncImage("file://" + backPath, ImgPhoto, false); BtnDel.gameObject.SetActive(true); } }, "选择图片", "image/*"); } } else if (actionPick == NativeAction.Camera) { NativeGallery.Permission rest = NativeGallery.RequestIPhonePermission(4); if (rest == NativeGallery.Permission.Granted) { NativeGallery.GetIPhoneCameraImageFromGallery((backPath) => { if (backPath.IsNotNullAndEmpty()) { mPhotoPath = backPath; ImageDownloadUtils.Instance.SetAsyncImage("file://" + backPath, ImgPhoto, false); BtnDel.gameObject.SetActive(true); } }, "选择图片", "image/*"); } } #else #endif }
public void PickImage_2() { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { if (path != null) { rawImage_2.texture = NativeGallery.LoadImageAtPath(path); } }, "Select a PNG image", "image/png"); }
public void ChooseImage() { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { if (path != null) { targetManager.CreateNewTarget(path); } }, "Select a PNG image"); }
public static void Select(NativeGallery.MediaPickCallback callback) { // Checks that another media pick operation is not already in progress if (!NativeGallery.IsMediaPickerBusy()) { NativeGallery.Permission permission = NativeGallery.GetImageFromGallery(callback, "Select a PNG image", "image/png", _maxSize); Debug.Log("Permission result: " + permission); } }
public void TakePic() { if (NativeGallery.IsMediaPickerBusy()) { return; } _currentLoadedPicture = null; _fileName = null; //#if UNITY_EDITOR // //System.Windows.Forms.OpenFileDialog openFileDialog; // //openFileDialog = new System.Windows.Forms.OpenFileDialog() // //{ // // InitialDirectory = @"D:\", // // Title = "Browse Text Files", // // CheckFileExists = true, // // CheckPathExists = true, // // DefaultExt = "png", // // Filter = "png files (*.png)|*.jpg", // // FilterIndex = 2, // // RestoreDirectory = true, // // ReadOnlyChecked = true, // // ShowReadOnly = true // //}; // //if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) // //{ // // Debug.Log(openFileDialog.FileName); // // var fileData = System.IO.File.ReadAllBytes(openFileDialog.FileName); // // _currentLoadedPicture = new Texture2D(2, 2); // // _currentLoadedPicture.LoadImage(fileData); //..this will auto-resize the texture dimensions. // // _fileName = openFileDialog.SafeFileName; // //} // OnPictureLoad(_currentLoadedPicture); //#elif UNITY_ANDROID NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((string path) => { if (path != null) { // Create Texture from selected image _currentLoadedPicture = NativeGallery.LoadImageAtPath(path); _fileName = Path.GetFileName(path); OnPictureLoad(_currentLoadedPicture); } }, "", "image/*"); //#endif }
public void ChooseVideo() { NativeGallery.Permission permission = NativeGallery.GetVideoFromGallery((path) => { TargetBehavior target = FindObjectOfType <TargetBehavior>(); if (path != null && target != null) { target.OnVideoChosen(path); } }, "Select a video'"); }