public ImageCropper.Settings GetImageSettings() { ImageCropper.Settings result = new ImageCropper.Settings(); result.markTextureNonReadable = false; result.selectionMinAspectRatio = result.selectionMaxAspectRatio = (float)imageWidth / imageHeight; return(result); }
// Update is called once per frame private void Update() { if (cameraTestMode) { if (inputEnabled && (Input.GetKeyDown("space") || Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)) { if (cameraPanel.activeSelf) { inputEnabled = false; var texture = cameraPanel.GetComponent <Image>().material.mainTexture as WebCamTexture; var settings = new ImageCropper.Settings(); var texture2D = new Texture2D(texture.width, texture.height); settings.selectionMinAspectRatio = settings.selectionMaxAspectRatio = 1; texture2D.SetPixels(texture.GetPixels()); texture2D.Apply(); //ImageCropper.ImageResizePolicy policy = new ImageCropper.ImageResizePolicy(TargetWidth,targetHeight); ImageCropper.Instance.Show(texture2D, cropResult, settings, ImageResizePolicy); if (false) { Debug.Log(texture.GetType()); Debug.Log(texture.width + " " + texture.height); cameraPanel.GetComponent <RectTransform>().rect.Set(0, 0, texture.width, texture.height); /* */ //IntPtr pointer = texture.GetNativeTexturePtr(); //texture2D.UpdateExternalTexture(pointer); texture2D.SetPixels(texture.GetPixels()); texture2D.Apply(); } //LocationPanel.GetComponent<Image>().sprite = Sprite.Create(texture2D,new Rect(0,0,texture2D.width,texture2D.height),new Vector2(0.5f,0.5f)); } Debug.Log("Space pressed"); cameraPanel.SetActive(!cameraPanel.activeSelf); } } }