/// <summary> /// /// </summary> public void TakeSnapshotWebcam() { // No device detected!! // cannot take snap shot without the device!! if (!mDetectDevice) { JCS_Debug.LogError("JCS_Webcam", "No webcam detected in the current devices."); return; } string fullPath = Application.dataPath + mSavePath; // if Directory does not exits, create it prevent error! if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } Texture2D snap = new Texture2D(mWebCamTexture.width, mWebCamTexture.height); snap.SetPixels(mWebCamTexture.GetPixels()); snap.Apply(); System.IO.File.WriteAllBytes(fullPath + mCaptureCounter.ToString() + ".png", snap.EncodeToPNG()); ++mCaptureCounter; if (mSplash) { JCS_SceneManager sm = JCS_SceneManager.instance; if (sm.GetJCSWhiteScreen() == null) { JCS_UtilityFunctions.PopJCSWhiteScreen(); } sm.GetJCSWhiteScreen().FadeIn(); // do the snap shot effect mSplashEffectTrigger = true; } // Stop the camera mWebCamTexture.Stop(); // start the timer wait for resume mResumeTrigger = true; // play sound. mSoundPlayer.PlayOneShot(mTakePhotoSound); }
/// <summary> /// Take a snapshot and store image to data path. /// </summary> public string TakeSnapshotWebcam() { // No device detected!! // cannot take snap shot without the device!! if (!mDetectDevice) { JCS_Debug.LogError("No webcam detected in the current devices"); return(null); } var gs = JCS_GameSettings.instance; var prefix = gs.WEBCAM_FILENAME; var ext = gs.WEBCAM_EXTENSION; string savePath = SavePath(); JCS_IO.CreateDirectory(savePath); Texture2D snap = new Texture2D(mWebCamTexture.width, mWebCamTexture.height); snap.SetPixels(mWebCamTexture.GetPixels()); snap.Apply(); // get the last saved webcam image's index int last_saved_index = LastImageFileIndex() + 1; string fullPath = ImagePathByIndex(last_saved_index); File.WriteAllBytes(fullPath, snap.EncodeToPNG()); if (mSplash) { JCS_SceneManager sm = JCS_SceneManager.instance; if (sm.GetJCSWhiteScreen() == null) { JCS_UtilityFunctions.PopJCSWhiteScreen(); } sm.GetJCSWhiteScreen().FadeIn(); // do the snap shot effect mSplashEffectTrigger = true; } // Stop the camera mWebCamTexture.Pause(); // start the timer wait for resume mResumeTrigger = true; // play sound. { var soundm = JCS_SoundManager.instance; JCS_SoundPlayer sp = soundm.GetGlobalSoundPlayer(); sp.PlayOneShot(mTakePhotoSound); } return(fullPath); }