private IEnumerator OnScreenShot() { CheckButtonActive = false; m_state.CheckTouchActive = false; OnOffUI(false); m_state.SetDogAnimation(false); yield return(new WaitForSeconds(0.75f)); Texture2D screenShot = null; RenderImageCallback renderImage = m_state.GetCurCamera().gameObject.AddComponent <RenderImageCallback>(); bool isDepthOnly = m_state.GetCurCamera().gameObject.GetComponent <Camera>().clearFlags.Equals(CameraClearFlags.Depth); renderImage.Init(isDepthOnly, delegate(Texture2D texture) { screenShot = texture; }); while (screenShot == null) { yield return(null); } m_uiPhotoStudioResult.SetActive(true); yield return(StartCoroutine(m_uiPhotoStudioResult.OnDirectionWindow(screenShot))); CheckButtonActive = true; }
///<summary>Handles rendering to the PictureBox of the image in its current state. The image calculations are not performed here, only rendering of the image is performed here, so that we can guarantee a fast display.</summary> private void RenderCurrentImage(Document docCopy,int originalWidth,int originalHeight,float zoom,PointF translation) { if(!this.Visible) { return; } //Helps protect against simultaneous access to the picturebox in both the main and render worker threads. if(pictureBoxMain.InvokeRequired) { RenderImageCallback c=new RenderImageCallback(RenderCurrentImage); Invoke(c,new object[] { docCopy,originalWidth,originalHeight,zoom,translation }); return; } int width=pictureBoxMain.Bounds.Width; int height=pictureBoxMain.Bounds.Height; if(width<=0 || height<=0) { return; } Bitmap backBuffer=new Bitmap(width,height); Graphics g=Graphics.FromImage(backBuffer); try { g.Clear(pictureBoxMain.BackColor); g.Transform=GetScreenMatrix(docCopy,originalWidth,originalHeight,zoom,translation); g.DrawImage(ImageRenderingNow,0,0); if(RectCrop.Width>0 && RectCrop.Height>0) {//Must be drawn last so it is on top. g.ResetTransform(); g.DrawRectangle(Pens.Blue,RectCrop); } g.Dispose(); //Cleanup old back-buffer. if(pictureBoxMain.Image!=null) { pictureBoxMain.Image.Dispose(); //Make sure that the calling thread performs the memory cleanup, instead of relying //on the memory-manager in the main thread (otherwise the graphics get spotty sometimes). } pictureBoxMain.Image=backBuffer; pictureBoxMain.Refresh(); } catch(Exception) { g.Dispose(); } //Tried this. Program crashes when any small window is dragged across the picturebox. //backBuffer.Dispose(); //backBuffer=null; }
private IEnumerator OnScreenShot() { m_state.m_guiManager.CheckButtonActive = false; m_state.CheckTouchActive = false; m_uiWindow.OnOffButtonGroup(false); yield return(new WaitForSeconds(0.75f)); m_screenShot = null; if (m_state.CheckProfileImageChnage) { RenderImageCallback renderImage = StateManager.instance.m_curState.GetUICamera().gameObject.AddComponent <RenderImageCallback>(); bool isDepthOnly = StateManager.instance.m_curState.GetUICamera().gameObject.GetComponent <Camera>().clearFlags.Equals(CameraClearFlags.Depth); renderImage.Init(isDepthOnly, delegate(Texture2D texture) { m_screenShot = texture; }); while (m_screenShot == null) { yield return(null); } WorldManager.instance.AddMemoryInfo(WORLD_MEMORY_INFO.IMAGECROP_TEXTURE, m_screenShot); WorldManager.instance.AddMemoryInfo(WORLD_MEMORY_INFO.IMAGECROP_STATE, m_state.GetBeforeStateType); m_screenShot = null; StateManager.instance.SetTransition(STATE_TYPE.STATE_IMAGECROP); } else { UINgShareLogo logo = MsgBox.instance.MakeLogoPanel(); yield return(null); RenderImageCallback renderImage = MsgBox.instance.GetCameraTransform.gameObject.AddComponent <RenderImageCallback>(); bool isDepthOnly = MsgBox.instance.GetCameraTransform.gameObject.GetComponent <Camera>().clearFlags.Equals(CameraClearFlags.Depth); renderImage.Init(isDepthOnly, delegate(Texture2D texture) { m_screenShot = texture; }); while (m_screenShot == null) { yield return(null); } yield return(StartCoroutine(PluginManager.instance.InitImage(null))); try { #if UNITY_EDITOR string path = string.Format("{0}/Pictures", System.Environment.CurrentDirectory); System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(path); if (dInfo.Exists == false) { dInfo.Create(); } System.IO.File.WriteAllBytes(string.Format("{0}/Xiaowangwang_{1}.png", path, Util.GetNowGameTime()), m_screenShot.EncodeToPNG()); #else PluginManager.instance.SaveImageToGallery(m_screenShot, string.Format("Xiaowangwang_{0}", Util.GetNowGameTime()), ""); #endif } catch { } MsgBox.instance.OpenMsgToast(533); yield return(new WaitForSeconds(1.85f)); if (logo != null) { logo.Release(); } m_uiWindow.SwitchBotButtonGroup(true); m_uiWindow.OnOffBotButtonGroup(true); MsgBox.instance.OpenScreenShare(); m_state.m_guiManager.CheckButtonActive = true; } }