private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); text.text = "Image path: " + path; if (path != null) { // Create a Texture2D from the captured image Texture2D tex = NativeCamera.LoadImageAtPath(path, maxSize); if (tex == null) { Debug.Log("Couldn't load texture from " + path); return; } NativeGallery.SaveImageToGallery(tex, "GalleryTest", "My img {0}.png"); Sprite mySprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f); image.sprite = mySprite; } }, maxSize); Debug.Log("Permission result: " + permission); text.text += "\n Permission result:" + permission; }
private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize, false); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } PhotoTaken.texture = texture; PhotoTaken.gameObject.SetActive(true); imgPath = path; } }, maxSize); Debug.Log("Permission result: " + permission); }
// Need to download from assest store NATIVE CAMERA BY SULYMAN YASIR // https://github.com/yasirkula/UnityNativeCamera A nd follow this link inistruction on the READ ME File private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize, false); if (texture == null) { CaseNumberText.text = "Couldn't load texture from " + path; Debug.Log("Couldn't load texture from " + path); return; } // here put the taken picture inside the raw image photoTaken.texture = texture; photoTaken.gameObject.SetActive(true); imagepath = path; // CaseNumberText.text = "Image path: " + imagepath; } }, maxSize); Debug.Log("Permission result: " + permission); }
private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Photo Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize, false); if (texture == null) { Debug.Log("Camera Couldn't load texture from " + path); return; } else { mySprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f)); photoImage.GetComponent <Image>().sprite = mySprite; tookPhoto = true; } } }, maxSize); Debug.Log("Camera Permission result: " + permission); }
private void TakePictureWithNativeCamera(int MAX_SIZE) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { if (path != null) { Texture2D texture = NativeCamera.LoadImageAtPath(path, MAX_SIZE); if (texture == null) { return; } //キャンセルされたら実行せず imageGameobject.SetActive(true); uiNextGameObject.SetActive(true); uiStartGameOcject.SetActive(false); //縦横画像対応 //倍率の計算 var asW = (Mathf.Ceil((1920f / texture.width) * 10)) / 10; var asH = (Mathf.Ceil((1080f / texture.height) * 10)) / 10; var asM = Mathf.Max(asH, asW);//でかい方に picture.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); rect.sizeDelta = new Vector2(texture.width * asM, texture.height * asM); } }, MAX_SIZE); }
public async static Task <string> OpenImageDialog() { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR waitingForCallback = true; NativeCamera.Permission permission = NativeCamera.TakePicture((path) => GetImagePath(path)); await Task.Run(() => { while (waitingForCallback) { Thread.Sleep(100); } }); return(pathToReturn); #elif UNITY_EDITOR || UNITY_STANDALONE // Open file with filter ExtensionFilter[] extensions = new[] { new ExtensionFilter("Image Files", "png", "jpg", "jpeg") }; string[] paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, false); if (paths.Length == 0) { return(null); } else { return(paths[0]); } #elif UNITY_WSA return(null); #endif }
/// <summary> /// Open window for image pick. Work on IOS/Android /// </summary> public void UploadAvatarFromCamera() { if (NativeCamera.CheckPermission() != NativeCamera.Permission.Granted) { NativeCamera.RequestPermission(); } NativeCamera.TakePicture(OnImageTaken); }
/// <summary> /// uses NativeCamera lib /// </summary> /// <param name="maxSize"></param> public void TakePictureWithNativeCamera(int maxSize = 512) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); }, maxSize); Debug.Log("Permission result: " + permission); }
private void TakePicture() { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { if (!string.IsNullOrEmpty(path) && !string.IsNullOrWhiteSpace(path)) { ApplyMediaTreatment(path, true); } }, PICTURE_MAX_SIZE); }
public static void DeserializeCameraImage(bool p_saveToGallery) { FixInstanceName(); NativeCamera.CameraCallback v_cameraCallback = (path) => { Instance.NativeCameraPickedEnd(path, p_saveToGallery); }; NativeCamera.TakePicture(v_cameraCallback, CrossPickerServices.MaxImageLoadSize); }
private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { texture = NativeCamera.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } if (_PcdebugMode == false) { photoTaken.gameObject.SetActive(true); photoTaken.texture = texture; //Sending the image which user has taken in 64bit format to the backend byte[] currenBytes = DeCompress(texture).EncodeToJPG(); //bytes = _testTexture.EncodeToPNG(); string currentImage64 = "data:image/jpeg;base64," + Convert.ToBase64String(currenBytes); GameNetworkImage captured = new GameNetworkImage(_localUser.userID, currentImage64, _locationStatus.GetLocationLat(), _locationStatus.GetLocationLon()); StartCoroutine(_gameNetwork.PostAddObject("https://harryspotter.eu.ngrok.io/addObject", captured.Serialize().ToString(), GetObjectIds)); } /* * // 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); * * 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; * * Destroy(quad, 5f); * * // If a procedural texture is not destroyed manually, * // it will only be freed after a scene change * Destroy(texture, 5f); */ } else { _uIManagerMap.DisplayMapPanel(); } }, maxSize); Debug.Log("Permission result: " + permission); }
/// <summary> /// uses NativeCamera lib /// </summary> /// <param name="maxSize"></param> public void TakePictureWithNativeCameraAndShowIt(int maxSize = 512) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); PresentPhotoFromPathOnPhone(path, maxSize); }, maxSize); Debug.Log("Permission result: " + permission); }
public void /*IEnumerator*/ OnPressShowCamera() { /*yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); * WebCamTexture webCamTexture = new WebCamTexture(); * imageRenderer.material.mainTexture = webCamTexture; * webCamTexture.Play(); * //imageCamera.Show("Capture Image", "unimgpicker", 1024); */ int maxSize = 1024; NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.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); 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; Destroy(quad, 5f); // If a procedural texture is not destroyed manually, // it will only be freed after a scene change Destroy(texture, 5f); } }, maxSize); Debug.Log("Permission result: " + permission); }
public void TakePictureOnClick(int maxSize = -1) { NativeCamera.TakePicture((path) => { if (path == null) { return; } Texture2D texture = NativeCamera.LoadImageAtPath(path, 700, false); if (texture != null) { HandlePictureAddition(new List <Texture2D> { texture }); } }, maxSize); }
public static void TakePictureMission(int MaxSize, string MissionID, string Local) { NativeCamera.Permission Permission = NativeCamera.TakePicture((Path) => { Debug.Log("Path: " + Path); if (Path != null) { // string Format = System.IO.Path.GetExtension(Path); Texture2D Texture = DuplicateTexture(NativeCamera.LoadImageAtPath(Path, 1024)); if (Texture != null) { string PhotoName = FirebaseDatabase.DefaultInstance.GetReference("galeria-privada").Push().Key; string CloudPath = "galeria/" + PhotoName + ".png"; string DatabaseReference = "/galeria-privada/" + PhotoName; FirebaseController.WriteDataString(DatabaseReference, "usuario", FirebaseController.UserId); FirebaseController.WriteDataString(DatabaseReference, "email", FirebaseController.UserEmail); FirebaseController.WriteDataString(DatabaseReference, "nivel", TecWolf.Player.PlayerMission.Level.ToString()); FirebaseController.WriteDataString(DatabaseReference, "local", Local); FirebaseController.WriteDataString(DatabaseReference, "missao", MissionID); FirebaseController.WriteDataString(DatabaseReference, "formato", ".png"); // FirebaseStart.UploadFile(Path, CloudPath, Format, DownloadURL); FirebaseController.UploadByte(Texture.EncodeToPNG(), CloudPath, ".png", DatabaseReference); FirebaseController.WriteDataBool("/usuarios/" + FirebaseController.UserId + "/missoes/" + MissionID, "concluida", true); TecWolf.System.SystemSound.Effect.PlayOneShot(TecWolf.System.SystemSound.SoundsStatic[0]); FindObjectOfType <QuestInterface>().Refresh(); } Destroy(Texture); } }, MaxSize); #if UNITY_EDITOR FirebaseController.UploadFile(Application.dataPath + "/Test.jpg", "galeria/Test.jpg", ".jpg", "/galeria-privada/Test"); #endif Debug.Log("Permissão: " + Permission); }
private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { if (path != null) { Texture2D tex = NativeCamera.LoadImageAtPath(path, maxSize); if (tex == null) { Debug.Log("Couldn't load texture from " + path); return; } NativeGallery.SaveImageToGallery(tex, "GalleryTest", "My img {0}.png"); texturePhoto = tex; } }, maxSize); }
private void ResimCek(int maksimumBuyukluk) { NativeCamera.Permission izin = NativeCamera.TakePicture((konum) => { Debug.Log("Çekilen resmin konumu: " + konum); if (konum != null) { // Çekilen resmi bir Texture2D'ye çevir Texture2D texture = NativeCamera.LoadImageAtPath(konum, maksimumBuyukluk); if (texture == null) { Debug.Log(konum + " konumundaki resimden bir texture oluşturulamadı."); return; } // Texture'u geçici bir küp objesine ver //GameObject kup = GameObject.CreatePrimitive(PrimitiveType.Quad); //kup.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 5f; //kup.transform.forward = -Camera.main.transform.forward; //kup.transform.localScale = new Vector3(1f, texture.height / (float)texture.width, 1f); //Material material = kup.GetComponent<Renderer>().material; //if (!material.shader.isSupported) // eğer Standard shader desteklenmiyorsa Diffuse shader'ı kullan // material.shader = Shader.Find("Legacy Shaders/Diffuse"); RectTransform rectTransform = outputImage.GetComponent <RectTransform>(); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectTransform.rect.width * texture.height / texture.width); outputImage.texture = texture; //material.mainTexture = texture; // 5 saniye sonra küp objesini yok et //Destroy(kup, 5f); // Küp objesi ile birlikte Texture2D objesini de yok et // Eğer prosedürel bir objeyi (Texture2D) işiniz bitince yok etmezseniz, // mevcut scene'i değiştirene kadar obje hafızada kalmaya devam eder Destroy(texture, 5f); } }, maksimumBuyukluk); Debug.Log("İzin durumu: " + izin); }
/// <summary> /// 打开相机拍照 /// </summary> public static void OpenCamera(Action <string> callBack) { NativeCamera.Permission permission = NativeCamera.TakePicture((string path) => { if (!string.IsNullOrEmpty(path) && callBack != null) { callBack(path); } }); if (permission != NativeCamera.Permission.Granted) { ShowToast("当前没有相机访问权限,请在设置中打开"); //打开应用程序设置 if (NativeCamera.CanOpenSettings()) { NativeCamera.OpenSettings(); } } }
public void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } AddPicToGallery(texture); } }, maxSize); Debug.Log("Permission result: " + permission); }
public void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.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); 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; Destroy(quad, 5f); // If a procedural texture is not destroyed manually, // it will only be freed after a scene change Destroy(texture, 5f); } }, maxSize); Debug.Log("Permission result: " + permission + ", Taking Photo"); }
private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path == null) { return; } var texture = NativeGallery.LoadImageAtPath(path, maxSize, false, false); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } MediaController.ME.SendPhoto(texture); }, maxSize); Debug.Log("Permission result: " + permission); }
public void PedirImagen() { var permiso = NativeCamera.TakePicture(path => { if (!string.IsNullOrEmpty(path)) { if (imagenRecuperada) { Destroy(imagenRecuperada); } imagenRecuperada = NativeCamera.LoadImageAtPath(path, -1, false, false); alAbrirTextura.Invoke(imagenRecuperada); } }); if (permiso == NativeCamera.Permission.ShouldAsk) { if (NativeCamera.CanOpenSettings()) { NativeCamera.OpenSettings(); } } }
private void ResimCek(int maksimumBuyukluk) { NativeCamera.Permission izin = NativeCamera.TakePicture((konum) => { Debug.Log("Çekilen resmin konumu: " + konum); if (konum != null) { // Çekilen resmi bir Texture2D'ye çevir Texture2D texture = NativeCamera.LoadImageAtPath(konum, maksimumBuyukluk, false); if (texture == null) { Debug.Log(konum + " konumundaki resimden bir texture oluşturulamadı."); return; } outputImage.enabled = true; RectTransform rectTransform = outputImage.GetComponent <RectTransform>(); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectTransform.rect.width * texture.height / texture.width); data = Convert.ToBase64String(texture.EncodeToJPG()); fileSize = texture.EncodeToJPG().Length; outputImage.texture = texture; sendMedia(); // 5 saniye sonra küp objesini yok et //Destroy(kup, 5f); // Küp objesi ile birlikte Texture2D objesini de yok et // Eğer prosedürel bir objeyi (Texture2D) işiniz bitince yok etmezseniz, // mevcut scene'i değiştirene kadar obje hafızada kalmaya devam eder //Destroy(texture, 5f); } }, maksimumBuyukluk); Debug.Log("İzin durumu: " + izin); }
//Native Camera 에셋 -> https://github.com/yasirkula/UnityNativeCamera 지침 참조 private void TakePicture(int maxSize) { //안드로이드 카메라 권한 NativeCamera.Permission permission = NativeCamera.TakePicture((PATH) => { Debug.Log("Image path: " + PATH); if (PATH != null) { // 선택된 이미지의 Texture 생성 Texture2D texture = NativeCamera.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("nativecam " + bytes[0]); //path에 저장 FileStream fs = new FileStream(path + "test.png", FileMode.Create, FileAccess.Write); byte[] data = bytes; fs.Write(data, 0, (int)data.Length); Debug.Log("저장 완료"); fs.Close(); Destroy(texture, 5f); socket.instance.ImageServer_C(); } }, maxSize); Debug.Log("Permission result: " + permission); }
void ProcessImage(int maxSize) { preview.sprite = cameraIcon; NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize); if (texture == null) { Debug.Log("Couldn't load texture from " + path); return; } CropImage(texture); // Destroy(texture); } }, maxSize); Debug.Log("Permission result: " + permission); }
public void TakePicture() { NativeCamera.TakePicture(TakePictureCallback, 1024); }
private void TakePicture(int maxSize) { NativeCamera.Permission permission = NativeCamera.TakePicture((path) => { Debug.Log("Image path: " + path); m_LocalFileName = path.ToString(); int te = UnityEngine.Random.Range(11111, 9999999); imageId = te.ToString(); if (path != null) { // Create a Texture2D from the captured image Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize); // EditorUtility.CompressTexture(texture, TextureFormat.RGB24, TextureCompressionQuality.Normal); 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); * * * * 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); StartCoroutine(TakeScreenShot(ScreenShotGO, texture)); //CanvasGO.SetActive(false); //StartCoroutine(TakeScreenShot(CanvasGO,quad, texture)); // If a procedural texture is not destroyed manually, // it will only be freed after a scene change //Destroy(texture, 5f); //UploadImage(texture); } }, maxSize); Debug.Log("Permission result: " + permission); }