Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 3
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;
    }
Ejemplo n.º 4
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);
    }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
    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
    }
Ejemplo n.º 7
0
    /// <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);
 }
 private void RecordVideo()
 {
     NativeCamera.Permission permission = NativeCamera.RecordVideo((path) =>
     {
         if (!string.IsNullOrEmpty(path) && !string.IsNullOrWhiteSpace(path))
         {
             ApplyMediaTreatment(path, false);
         }
     });
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Android call contains 2 requests:
    /// Camera, Storage.
    /// </summary>
    private bool CheckPermissionOrRequestBase()
    {
        NativeCamera.Permission resultOfCheckPermission =
            NativeCamera.CheckPermission();

        DebugPrinter.Print("CheckCameraPermissionOrRequest");

        switch (resultOfCheckPermission)
        {
        case NativeCamera.Permission.Granted:

            DebugPrinter.Print("Camera Permission Granted");

            return(true);

        case NativeCamera.Permission.ShouldAsk:

            NativeCamera.Permission resultOfRequestPermission;

            do
            {
                resultOfRequestPermission =
                    NativeCamera.RequestPermission();

                DebugPrinter.Print(2);
            }while (resultOfRequestPermission
                    == NativeCamera.Permission.ShouldAsk);

            if (resultOfRequestPermission
                == NativeCamera.Permission.Granted)
            {
                DebugPrinter.Print(3.1f);

                return(true);
            }
            else
            {
                DebugPrinter.Print(3.2f);

                return(false);
            }

        case NativeCamera.Permission.Denied:

            DebugPrinter.Print(4);

            return(false);

        default:

            DebugPrinter.Print(5);

            return(false);
        }
    }
Ejemplo n.º 11
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);
    }
Ejemplo n.º 12
0
    /// <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);
    }
Ejemplo n.º 13
0
    private void RecordVideo()
    {
        NativeCamera.Permission permission = NativeCamera.RecordVideo((path) =>
        {
            Debug.Log("Video path: " + path);
            if (path != null)
            {
                StartCoroutine(LoadVideo(path));
            }
        });

        Debug.Log("Permission result: " + permission);
    }
Ejemplo n.º 14
0
    private void VideoKaydet()
    {
        NativeCamera.Permission izin = NativeCamera.RecordVideo((konum) =>
        {
            Debug.Log("Kaydedilen videonun konumu: " + konum);
            if (konum != null)
            {
                // Videoyu oynat
                Handheld.PlayFullScreenMovie("file://" + konum);
            }
        });

        Debug.Log("İzin durumu: " + izin);
    }
Ejemplo n.º 15
0
    private void RecordVideo()
    {
        NativeCamera.Permission permission = NativeCamera.RecordVideo((path) =>
        {
            Debug.Log("Video path: " + path);
            if (path != null)
            {
                // Play the recorded video
                Handheld.PlayFullScreenMovie("file://" + path);
            }
        });

        Debug.Log("Permission result: " + permission);
    }
Ejemplo n.º 16
0
    private void RecordVideo()
    {
        NativeCamera.Permission permission = NativeCamera.RecordVideo((path) =>
        {
            UnityEngine.Debug.Log("Video path: " + path + " is the path");
            if (path != null)
            {
                // Play the recorded video
                //Handheld.PlayFullScreenMovie("file://" + path);
            }
        });//, NativeCamera.Quality.Medium, 100, 100L, NativeCamera.PreferredCamera.Front);

        UnityEngine.Debug.Log("Permission result: " + permission);
    }
Ejemplo n.º 17
0
    // Records a video, using https://github.com/yasirkula/UnityNativeCamera
    private void RecordVideo()
    {
        gameObject.transform.Find("Explanation").gameObject.SetActive(false);
        if (NativeCamera.IsCameraBusy())
        {
            output.text = ("Camera Busy");
            return;
        }
        vidTime = DateTime.Now + new TimeSpan(0, 0, 4); // TODO can we do better than just "it'll start in 4 seconds"?

        NativeCamera.Permission permission = NativeCamera.RecordVideo(HandleVideo, NativeCamera.Quality.Low);

        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);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// 打开相机录像
 /// </summary>
 public static void OpenCameraVideo(Action <string> callBack)
 {
     NativeCamera.Permission permission = NativeCamera.RecordVideo((string path) =>
     {
         if (!string.IsNullOrEmpty(path) && callBack != null)
         {
             callBack(path);
         }
     });
     if (permission != NativeCamera.Permission.Granted)
     {
         ShowToast("当前没有相机访问权限,请在设置中打开");
         //打开应用程序设置
         if (NativeCamera.CanOpenSettings())
         {
             NativeCamera.OpenSettings();
         }
     }
 }
Ejemplo n.º 22
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();
         }
     }
 }
Ejemplo n.º 23
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);
    }
Ejemplo n.º 24
0
    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);
    }
Ejemplo n.º 25
0
    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 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");
    }
Ejemplo n.º 27
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);
    }
Ejemplo n.º 28
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);
    }
Ejemplo n.º 29
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);
    }
Ejemplo n.º 30
0
    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);
    }