Esempio n. 1
0
 /// <summary>
 /// Check if the suers has the proper android permissions to use the photo gallery
 /// </summary>
 void CheckPermissions()
 {
     if (NativeGallery.CheckPermission() == NativeGallery.Permission.ShouldAsk)
     {
         NativeGallery.RequestPermission();
     }
 }
Esempio n. 2
0
    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);
    }
Esempio n. 3
0
    public IEnumerator CaptureScreen()
    {
        // Wait till the last possible moment before screen rendering to hide the UI
        yield return(null);

        GameObject.Find("Canvas").GetComponent <Canvas>().enabled = false;

        // Wait for screen rendering to complete
        yield return(new WaitForEndOfFrame());

        ScreenCapture.CaptureScreenshot("screenshot.png");

        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();

        // NativeGallery.SaveImageToGallery(ss, "Screenshot", DateTime.Now.ToString().Replace("/", "-"));
        //  NativeGallery.SaveImageToGallery(ss, "Screenshot", "screenshot"+ ScreenCounter+".png");
        NativeGallery.SaveImageToGallery(ss, "Screenshot", "screenshot" + DateTime.Now.ToString().Replace("/", "-") + ".png");

        // To avoid memory leaks
        Destroy(ss);
        GameObject.Find("Canvas").GetComponent <Canvas>().enabled = true;
    }
Esempio n. 4
0
    /// <summary>
    /// Savings the capture image.
    /// </summary>
    /// <returns>The capture image.</returns>
    IEnumerator SavingCaptureImage()
    {
        yield return(new WaitForEndOfFrame());

        string path         = Application.persistentDataPath + "/";
        string saveFileName = m_FileName + GetDateString() + m_FileType;

        byte[] jpgData = m_TempScreenShot.EncodeToJPG();

                #if UNITY_EDITOR
        File.WriteAllBytes(saveFileName, jpgData);
        yield return(new WaitForEndOfFrame());

        OnCompleteCapture();
#elif UNITY_ANDROID
        if (UniAndroidPermission.IsPermitted(AndroidPermission.WRITE_EXTERNAL_STORAGE))
        {
            NativeGallery.SaveImageToGallery(jpgData, "ARCoreList", "Screenshot ARCoreList {0}.jpg");
        }
        else
        {
            OnCaptureFailed();
        }
#endif
    }
Esempio n. 5
0
    private void SetUpImgForCategory(GameName _game, string _categoryKey)
    {
        gameName    = _game;
        categoryKey = _categoryKey;

        var categoryData = categoryStorage.Categories[_categoryKey];

        Sprite sprite = null;

        NativeGallery.GetImageFromGallery((path) =>
        {
            if (path != null)
            {
                Texture2D texture = NativeGallery.LoadImageAtPath(path, -1, false);

                var size = (texture.width < texture.height) ? texture.width : texture.height;
                sprite   = Sprite.Create(texture, new Rect(0, 0, size, size), Vector2.zero);

                if (categoryData.IsCustom)
                {
                    UpdateCategoryImage(_categoryKey, sprite);
                }
                else
                {
                    SetUpImgToBaseCategory(_game, _categoryKey, sprite);
                }
            }
        });
    }
Esempio n. 6
0
    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);
    }
Esempio n. 7
0
    //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);
    }
Esempio n. 8
0
    //选择一个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);
    }
Esempio n. 9
0
    public void PickImage(Image _targetImg, int _imgNumber)
    {
        NativeGallery.GetImageFromGallery((path) =>
        {
            if (path != null)
            {
                Texture2D texture = NativeGallery.LoadImageAtPath(path, -1, false);
                if (texture == null)
                {
                    return;
                }

                var size          = (texture.width < texture.height) ? texture.width : texture.height;
                _targetImg.sprite = Sprite.Create(texture, new Rect(0, 0, size, size), Vector2.zero);

                if (_imgNumber == 1)
                {
                    image1data = texture;
                }
                if (_imgNumber == 2)
                {
                    image2data = texture;
                }
                if (_imgNumber == 3)
                {
                    image3data = texture;
                }
            }
        });
    }
Esempio n. 10
0
    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);
    }
Esempio n. 11
0
 /// <summary>
 /// OnGUI is called for rendering and handling GUI events.
 /// This function can be called multiple times per frame (one call per event).
 /// </summary>
 void OnGUI()
 {
     if (GUILayout.Button("Save Galler/Photos", GUILayout.Width(100), GUILayout.Height(100)))
     {
         StartCoroutine(TakeScreenshotAndSave());
     }
     if (GUILayout.Button("Pick Image", GUILayout.Width(100), GUILayout.Height(100)))
     {
         //另一个媒体选择器占用了进程
         if (NativeGallery.IsMediaPickerBusy())
         {
             return;
         }
         PickImage(512);
     }
     if (GUILayout.Button("Pick Video", GUILayout.Width(100), GUILayout.Height(100)))
     {
         //另一个媒体选择器占用了进程
         if (NativeGallery.IsMediaPickerBusy())
         {
             return;
         }
         PickVideo();
     }
 }
    IEnumerator CaptureIt()
    {
        btnShot.SetActive(false);
        btnCloseMenu.SetActive(false);
        Camera.main.cullingMask = -1;
        yield return(new WaitForSeconds(1f));

        // prepare texture with Screen and save it
        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        texture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height), 0, 0);
        texture.LoadRawTextureData(texture.GetRawTextureData());
        texture.Apply();
        // save to persistentDataPath File
        byte[] data        = texture.EncodeToJPG(85);
        string destination = Path.Combine(Application.persistentDataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".jpg");

        File.WriteAllBytes(destination, data);

        Sprite sp = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height),
                                  new Vector2(0.5f, 0.5f));

        canvas.GetComponent <Image>().sprite = sp;
        canvas.SetActive(true);
        toSave = destination;

        NativeGallery.SaveImageToGallery(texture, "ARCoreList", "Screenshot ARCoreList {0}.jpg");

        yield return(new WaitForSeconds(1f));

        canvas.SetActive(false);
        btnShot.SetActive(true);
        btnCloseMenu.SetActive(true);
    }
Esempio n. 13
0
    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");
    }
Esempio n. 14
0
    /// <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);
    }
Esempio n. 15
0
    /// <summary>
    /// shows an image from the phone gallery on a canvas
    /// uses NativeGallery
    /// </summary>
    /// <param name="_path"></param>
    /// <param name="_maxsize"></param>
    private void PresentPhotoFromPathOnPhone(string _path, int _maxsize)
    {
        // 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);

        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);
    }
Esempio n. 16
0
    public static IEnumerator CaptureAndShowPreviewImage(Texture2D imageTexture = null)
    {
        yield return(new WaitForEndOfFrame()); // Wait for rendering.

        byte[] bytes = imageTexture == null?GetBytesOfScreenshot() : imageTexture.EncodeToPNG();

        string path;
        string imageName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".png"; // Set image name.

#if UNITY_ANDROID
        path = androidGalleryPath;
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        SaveImageToAndroidGallery(path + imageName, bytes); // Write bytes and refresh android gallery.
        previewGameObject.SetActive(true);
        ShowPreview(path + imageName);
#elif UNITY_IOS
        path = Application.persistentDataPath + "/";
        NativeGallery.SaveImageToGallery(bytes, galleryFolderName, imageName);         // User plugin.
        previewGameObject.SetActive(true);
        ShowPreview(path + imageName);
#elif UNITY_EDITOR
        path = windowsImageSavePath;
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        SaveImageToWindow(path + imageName, bytes);
#endif
    }
Esempio n. 17
0
 /// <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();
         }
     }
 }
Esempio n. 18
0
 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);
 }
Esempio n. 19
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (Input.mousePosition.x < Screen.width / 3)
            {
                // Take a screenshot and save it to Gallery/Photos
                StartCoroutine(TakeScreenshotAndSave());
            }
            else
            {
                // Don't attempt to pick media from Gallery/Photos if
                // another media pick operation is already in progress
                if (NativeGallery.IsMediaPickerBusy())
                {
                    return;
                }

                if (Input.mousePosition.x < Screen.width * 2 / 3)
                {
                    // Pick a PNG image from Gallery/Photos
                    // If the selected image's width and/or height is greater than 512px, down-scale the image
                    PickImage(512);
                }
                else
                {
                    // Pick a video from Gallery/Photos
                    PickVideo();
                }
            }
        }
    }
Esempio n. 20
0
    private IEnumerator TakeScreenshotAndSave()
    {
        GameObject.Find("CaptureCanvas").GetComponent <Canvas>().enabled = false;
        TakeShotWithKids(Kids, 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();

        GameObject bl = Instantiate(blink) as GameObject;

        bl.transform.SetParent(blParent.transform, false);

        GameObject.Find("CaptureCanvas").GetComponent <Canvas>().enabled = true;

        TakeShotWithKids(Kids, true);

        string className = "EduApp_Social";
        string name      = string.Format("{0}_Capture{1}_{2}.png", className, "{0}", System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));

        Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, className + " Captures", name));
        //Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, "GalleryTest", "My img{0}.png"));
        Destroy(ss);
    }
Esempio n. 21
0
    private void HandleVideo(string tempPath)
    {
        if (tempPath == null || tempPath == "")
        {
            output.text = "Recording failed";
            StartCoroutine(ResetText());
            return;
        }

        string filename = vidTime.ToString("yyyyMMdd_HHmmss") + Path.GetExtension(tempPath);

        output.text = "Video Recorded: " + filename;

        NativeGallery.SaveVideoToGallery(tempPath, "augKlimb", filename);

        string newPath = Path.Combine(Path.GetDirectoryName(tempPath), filename);

        File.Move(tempPath, newPath);
        Debug.Log(newPath);

        shareButton.SetActive(true);
        shareButton.GetComponent <Button>().onClick.AddListener(delegate
        {
            new NativeShare().AddFile(newPath).Share();
        });
    }
Esempio n. 22
0
    IEnumerator CaptureIt()
    {
        yield return(new WaitForSeconds(0.5f));

        // prepare texture with Screen and save it
        Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        texture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height), 0, 0);
        texture.LoadRawTextureData(texture.GetRawTextureData());
        texture.Apply();

        // save to persistentDataPath File
        byte[] data        = texture.EncodeToPNG();
        string destination = Path.Combine(Application.persistentDataPath,
                                          System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png");

        File.WriteAllBytes(destination, data);

        Sprite sp = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height),
                                  new Vector2(0.5f, 0.5f));

        canvas.GetComponent <Image>().sprite = sp;

        toSave = destination;

        NativeGallery.SaveImageToGallery(texture, "testAR_Trofymchuk", "Screenshot testAR_Trofymchuk {0}.png");
        Instantiate(blink, new Vector2(0f, 0f), Quaternion.identity);
        shotMenu.SetActive(true);
    }
Esempio n. 23
0
        private void StartResquestForDelBabyAddress()
        {
            Dictionary <string, object> paramDict = new Dictionary <string, object>();

            paramDict.Add("inviteId", PlayerPrefsUtil.GetUserId());
            paramDict.Add("inviteeMobile", InputMobile.text);
            paramDict.Add("inviteeBabyRelation", relation);
            HttpUtil.PostWithSign <int>(UrlConst.DoCheckInviteValid, paramDict)
            .Subscribe(response =>
            {
                if (response == 1)
                {
                    Dictionary <string, object> message = new Dictionary <string, object>();
                    message.Add("mobile", InputMobile.text);
                    message.Add("content", "【环球少儿app】邀请你加入,快来跟我一起读绘本吧!");
                    NativeGallery.GetSomethingFromNative((json, action) =>
                    {
                    }, (int)NativeAction.SendSMS, message.ToJson());
                }
                CommonUtil.toast("邀请成功");
                SimpleEventSystem.Publish(new UpdateBaseInfoDate(true));
                Back();
            }
                       , e =>
            {
                if (e is HttpException)
                {
                    HttpException http = e as HttpException;
                    Log.E("弹吐司" + http.Message);
                }
            }).AddTo(this);
        }
  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;
  }
    // 스크린샷 찍고 갤러리에 갱신
    void ScreenshotAndGallery()
    {
        // 스크린샷
        // 2d 텍스쳐객체 > 넓이, 높이, 포멧 RGB24 설정, true?false?
        Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);

        Debug.Log("ss 설정");
        // 현재 화면을 픽셀단위로 읽음
        ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        Debug.Log("ss.ReadPixels");

        // 적용
        ss.Apply();
        Debug.Log("ss.Apply()");


        // 갤러리갱신
        Debug.Log("" + NativeGallery.SaveImageToGallery(ss, albumName,
                                                        "Screenshot_" + System.DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".png"));

        // To avoid memory leaks.
        // 복사 완료됐기 때문에 원본 메모리 삭제
        Destroy(ss);
        Debug.Log("ScreenshotAndGallery() 완료");
    }
Esempio n. 26
0
    private IEnumerator TakeSnapShot()
    {
        yield return(new WaitForEndOfFrame());

        Texture2D snapShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);

        snapCam.Render();

        RenderTexture.active = snapCam.targetTexture;

        snapShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);

        byte[] bytes = snapShot.EncodeToPNG();

        string fileName = string.Format("{0}_{1}.png", Application.dataPath, Application.productName, System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));

        NativeGallery.SaveImageToGallery(bytes, Application.dataPath, fileName);


        snapCam.targetTexture = null;

        fleshImage.SetActive(true);

        GetComponent <AudioSource>().Play();

        yield return(new WaitForSeconds(.5f));

        fleshImage.SetActive(false);
    }
Esempio n. 27
0
    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);
    }
Esempio n. 28
0
    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);
    }
Esempio n. 29
0
    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);
    }
Esempio n. 30
0
 public void Share()
 {
     NativeGallery.SaveImageToGallery(PhotoFilePath, "TestAR", "Screenshot.png");
     myNativeShare = new NativeShare();
     myNativeShare.AddFile(PhotoFilePath);
     myNativeShare.Share();
 }