Beispiel #1
0
 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);
 }
    private void TakePictureCallback(string path)
    {
        if (path != null)
        {
            // Create a Texture2D from the captured image in the cache
            Texture2D texture = NativeCamera.LoadImageAtPath(path, 1024);

            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }

            // create sprite from the texture
            Sprite newSprite = Sprite.Create(texture, new Rect(Vector2.zero, new Vector2(texture.width, texture.height)), new Vector2(.5f, .5f));

            if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
            {
                Permission.RequestUserPermission(Permission.ExternalStorageWrite);
            }

            if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
            {
                NotificationManager.Instance.ShowNotification("External Write Permission Required");
                return;
            }

            PathOfCurrentImage = NativeToolkit.SaveImage(texture, "Recipes");

            print($"CameraManager: Path of Image {PathOfCurrentImage}");

            OnPictureTaken?.Invoke(newSprite);
        }
    }
Beispiel #3
0
    public void ProcessInfo()
    {
        //Create a 2D Texture
        // and then to Apply the texture from image Path
        // encode to PNG
        // store bytes to photo taken of the active case

        // false to make the texture is readable 0
        byte[] imgData = null;
        if (string.IsNullOrEmpty(imagepath) == false)
        {
            Texture2D img = NativeCamera.LoadImageAtPath(imagepath, 512, false);
            imgData = img.EncodeToPNG();
        }

        UIManager.instance.ActiveCase.phototaken = imgData;
        //Texture2D convertedPhoto = photoTaken.texture as Texture2D;
        //byte[] imgData = convertedPhoto.EncodeToPNG();



        if (string.IsNullOrEmpty(PhotoNotes.text) == false)
        {
            UIManager.instance.ActiveCase.photoNotes = PhotoNotes.text;
        }



        overviewPanel.SetActive(true);
        borderPanel.SetActive(true);
    }
Beispiel #4
0
    void SetImageFromPath(string path)
    {
        int maxSize = 64;

        if (path != null)
        {
            Texture2D texture = NativeCamera.LoadImageAtPath(path, maxSize);

            if (texture == null)
            {
                Debug.Log("Couldn't load texture from " + path);
                return;
            }


            GameObject go = Instantiate(ImageGO);

            Rect rec = new Rect(0, 0, texture.width, texture.height);
            go.GetComponent <Image>().sprite = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);

            go.transform.SetParent(ImagePlace.transform);
            go.transform.position   = ImagePlace.position;
            go.transform.localScale = ImagePlace.localScale;
            go.transform.Find("Index").gameObject.GetComponent <Text>().text = index.ToString();
            string t = index.ToString();
            go.transform.Find("CloseButton").gameObject.GetComponent <Button>().onClick.AddListener(() => DeleteImageFromPhoneAndServer(t));

            //Update List from path if Exist
            int pathIndex = GetIndexFromPathList(path);
            imageStore[pathIndex].TextureImage = texture;
            imageStore[pathIndex].Index        = index;

            index++;
        }
    }
Beispiel #5
0
    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);
    }
Beispiel #6
0
    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);
    }
Beispiel #7
0
    // 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);
    }
        protected virtual void NativeImagePickedEnd(string p_path)
        {
            var v_texture           = !string.IsNullOrEmpty(p_path)? NativeCamera.LoadImageAtPath(p_path, -1, false) : null;
            var v_temporarySavePath = CrossPickerServices.SaveTextureToTemporaryPath(v_texture);

            CrossPickerServices.CallPickerFinishEvent(v_temporarySavePath, v_texture);
        }
Beispiel #9
0
    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;
    }
Beispiel #10
0
    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);
    }
    public void ProcessInfo()
    {
        byte[] imgData = null;

        if (!string.IsNullOrEmpty(imgPath))
        {
            Texture2D img = NativeCamera.LoadImageAtPath(imgPath, 512, false);
            imgData = img.EncodeToPNG();
        }

        UIManager.Instance.activeCase.photoNotes = photoNotesInput.text;
        UIManager.Instance.activeCase.photoTaken = imgData;
        overviewPanel.SetActive(true);
    }
Beispiel #12
0
    public static Sprite LoadNewSprite(string filePath, float pixelsPerUnit = 100.0f)
    {
        // Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference

        Sprite NewSprite;

#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
        Texture2D SpriteTexture = NativeCamera.LoadImageAtPath(filePath, 500, false);
#elif UNITY_EDITOR || UNITY_STANDALONE
        Texture2D SpriteTexture = LoadTexture(filePath);
#endif
        NewSprite = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0, 0), pixelsPerUnit);

        return(NewSprite);
    }
Beispiel #13
0
    public void ProcessInfo()
    {
        //convert it to byte array and store it
        byte[] imgData = null;

        if (!string.IsNullOrEmpty(_imgPath))
        {
            Texture2D img = NativeCamera.LoadImageAtPath(_imgPath, 512, false);
            imgData = img.EncodeToPNG();
        }

        UIManager.Instance.ActiveCase.PhotoTaken = imgData;
        UIManager.Instance.ActiveCase.PhotoNotes = _photoNotes.text;

        _overviewPanel.SetActive(true);
    }
    public void ProcessInfo()
    {
        //Create a 2D texture
        //Apply the texture to image patth
        //encode to PNG
        //store bytes to PhotoTaken
        if (string.IsNullOrEmpty(imgPath) == false)
        {
            Texture2D img     = NativeCamera.LoadImageAtPath(imgPath, 512, false);
            byte[]    imgData = img.EncodeToPNG();
            UIManager.Instance.activeCase.photoTaken = imgData;
        }

        UIManager.Instance.activeCase.photoNotes = photoNotes.text;
        OverviewPanel.Instance.SetOverviewPanel();
    }
        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);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
    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);
    }
Beispiel #18
0
        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);
        }
Beispiel #19
0
 /// <summary>
 /// 打开相机拍照
 /// </summary>
 public static void OpenCamera(Action <Texture2D> callBack)
 {
     NativeCamera.Permission permission = NativeCamera.TakePicture((string path) =>
     {
         if (!string.IsNullOrEmpty(path) && callBack != null)
         {
             callBack(NativeCamera.LoadImageAtPath(path));
         }
     });
     if (permission != NativeCamera.Permission.Granted)
     {
         ShowToast("当前没有相机访问权限,请在设置中打开");
         //打开应用程序设置
         if (NativeCamera.CanOpenSettings())
         {
             NativeCamera.OpenSettings();
         }
     }
 }
    public void ProcessInfo()
    {
        //UIManager.Instance.activeCase.photoTaken = photoTaken.texture;
        //Texture2D convertedPhoto = photoTaken.texture as Texture2D; // convert texture to texture2d
        //byte[] imgData = convertedPhoto.EncodeToPNG(); // convert to bytes

        byte[] imgData = null;

        if (string.IsNullOrEmpty(imgPath) == false)
        {
            Texture2D img = NativeCamera.LoadImageAtPath(imgPath, 512, false); // create 2D Texture + apply texture from image path
            imgData = img.EncodeToPNG();                                       // convert to bytes the encoded image
        }

        UIManager.Instance.activeCase.photoTaken = imgData;

        UIManager.Instance.activeCase.photoNotes = photoNotes.text;
        overviewPanel.SetActive(true);
    }
Beispiel #21
0
    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);
    }
    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);
    }
Beispiel #23
0
    public void ProcessInfo()
    {
        //Create a 2D Texture
        //Apply the Texture from image path
        //encode to PNG
        //store bytes to PhotoTaken

        byte[] imgData = null;

        if (!string.IsNullOrEmpty(imgPath))
        {
            Texture2D img = NativeCamera.LoadImageAtPath(imgPath, 512, false);

            imgData = img.EncodeToPNG();
        }

        UIManager.Instance.activeCase.photoNotes = photoNotes.text;
        UIManager.Instance.activeCase.photoTaken = imgData;

        overviewContainer.SetActive(true);
    }
Beispiel #24
0
    public void ProcessInfo()
    {
        if (string.IsNullOrEmpty(photoNotes.text) == false)
        {
            //convert it to byte array and store it it in photo taken
            //Convert Tesxture to Texture2D
            //Converty to byte
            byte[] imgData = null;
            if (string.IsNullOrEmpty(imgPath) == false)
            {
                Texture2D img = NativeCamera.LoadImageAtPath(imgPath, 512, false);
                imgData = img.EncodeToPNG();
            }

            UIManager.Instance.activeCase.PhotoTaken = imgData;
            UIManager.Instance.activeCase.PhotoNotes = photoNotes.text;
        }


        mainMenu.OpenPanel("OVERVIEW");
    }
    private void ApplyMediaTreatment(string path, bool isPicture)
    {
        mediaPropertiesButton.interactable = true;
        mediaPropertiesButton.onClick.RemoveAllListeners();

        if (isPicture)
        {
            Texture2D texture = NativeCamera.LoadImageAtPath(path, PICTURE_MAX_SIZE);
            if (CheckAndApplyTexture(path, texture))
            {
                mediaPropertiesButton.onClick.AddListener(() =>
                {
                    string imageName = StringUtils.GetMediaName(path);
                    propertiesPanel.ShowImageProperties(imageName, NativeCamera.GetImageProperties(path));
                });
            }

            playVideoButton.gameObject.SetActive(false);
        }
        else
        {
            Texture2D texture = NativeCamera.GetVideoThumbnail(path, PICTURE_MAX_SIZE);
            if (CheckAndApplyTexture(path, texture))
            {
                mediaPropertiesButton.onClick.AddListener(() =>
                {
                    string videoName = StringUtils.GetMediaName(path);
                    propertiesPanel.ShowVideoProperties(videoName, NativeCamera.GetVideoProperties(path));
                });
            }

            playVideoButton.gameObject.SetActive(true);
            playVideoButton.onClick.RemoveAllListeners();
            playVideoButton.onClick.AddListener(() =>
            {
                string filePath = string.Format("file://{0}", path);
                Handheld.PlayFullScreenMovie(filePath);
            });
        }
    }
    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");
    }
Beispiel #27
0
    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();
            }
        }
    }
Beispiel #28
0
    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);
    }
Beispiel #29
0
    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);
    }
Beispiel #30
0
    //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);
    }