/// <summary> /// Takes everything the recorder has seen so far and builds a recording from it, without stopping the recording process. /// </summary> /// <returns>A recording representing everything we've seen up until this point in time.</returns> /// <exception cref="System.InvalidOperationException">Thrown when the recorder is stopped.</exception> public Recording BuildRecording() { if (CurrentlyStopped()) { throw new System.InvalidOperationException("Not recording anything! Nothing to build!"); } if (CurrentlyPaused()) { pauseSlices.Add(new Vector2(timePaused, Time.time)); } var recordings = new SubjectRecording[subjectsToRecord.Count]; for (int i = 0; i < recordings.Length; i++) { recordings[i] = subjectsToRecord[i].Save(timeStarted, Time.time, pauseSlices); } Recording recording = Recording.CreateInstance(recordings, CaptureUtil.FilterAndShift(customEvents, timeStarted, Time.time, pauseSlices), metadata); if (CurrentlyPaused()) { pauseSlices.RemoveAt(pauseSlices.Count - 1); } return(recording); }
/// <summary> /// キャプチャを実行する /// </summary> internal void ExecuteCapture(int index) { try { string imagePath = CaptureUtil.GetScreenTrimmingImagePath(Screen.PrimaryScreen, Screen.PrimaryScreen.Bounds); if (imagePath != null) { switch (index) { case 0: if (ImageChoicePanel.Visible) { ImageList[GetSelectedImageIndex()] = new Bitmap(Image.FromFile(imagePath)); CaptureImage.Image = ImageList[GetSelectedImageIndex()]; } else { ImageList[0] = new Bitmap(Image.FromFile(imagePath)); CaptureImage.Image = ImageList[0]; } break; default: ImageList[1] = new Bitmap(Image.FromFile(imagePath)); CaptureImage.Image = ImageList[1]; break; } } } catch (Exception ex) { throw Program.ThrowException(ex); } }
private static void Main(string[] args) { //var r = CaptureUtil.DefGetCaptureData(ref offset, ref width, ref height); IntPtr hwnd = IntPtr.Zero; IntPtr hdc = IntPtr.Zero; if (CaptureUtil.GetWindowHDC(ref hwnd, ref hdc)) { int x = 0; int y = 0; CaptureUtil.GetWindowSize(hwnd, ref x, ref y); // 4k / 4 = 1k // sqrt(1024) = 32 int num = 0; const int blockSize = 128; var bitmap = new BITMAP(); var bitmapSize = CaptureUtil.DefGetCaptureBlockBitmap(hwnd, hdc, 0, 0, blockSize, blockSize, ref bitmap); int blockSizeW = (x + blockSize - 1) / blockSize; int blockSizeH = (y + blockSize - 1) / blockSize; for (int i = 0; i < blockSizeW; ++i) { for (int j = 0; j < blockSizeH; ++j) { var r = CaptureUtil.DefGetCaptureData(hwnd, hdc, bitmapSize, bitmap, i * blockSize, j * blockSize, blockSize, blockSize); var result = CaptureUtil.ConvertBmpToJpeg(r); using (FileStream fs = new FileStream(@"D:\Test\test" + num + @".jpg", FileMode.Create, FileAccess.Write)) { fs.Write(result, 0, result.Length); } ++num; } } } }
private void Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Image bitmap = null; var windowHandle = Win32.GetForegroundWindow(); Win32.RECT windowRect = new Win32.RECT(); Win32.GetWindowRect(windowHandle, out windowRect); if (isWindowOffScreen(windowRect)) { //useOtherPrint(); } else { bitmap = CaptureUtil.CaptureWindowBitBlt(windowHandle); } if (bitmap == null) { return; } BeginInvoke((MethodInvoker)(() => { this.pictureBox1.Height = bitmap.Height; this.pictureBox1.Width = bitmap.Width; this.Height = bitmap.Height + FormHeightMargin; this.Width = bitmap.Width + FormWidthMargin; this.pictureBox1.Image = bitmap; this.Invalidate(); }), bitmap); }
private static void Main(string[] args) { var result = CaptureUtil.ConvertBmpToJpeg(CaptureUtil.DefGetCaptureData()); using (FileStream fs = new FileStream(@"D:\test.jpg", FileMode.Create, FileAccess.Write)) { fs.Write(result, 0, result.Length); } Console.ReadKey(); }
/// <summary> /// Takes what events have been witnessed up until now and builds a recording from them. /// </summary> /// <param name="startTime">The minimum timestamp the events must have.</param> /// <param name="endTime">The maximum timestamp the events can have.</param> /// <param name="pauseSlices">Any time ranges you want to exclude events from in the final recording.</param> /// <returns></returns> public SubjectRecording Save(float startTime, float endTime, IEnumerable <Vector2> pauseSlices) { return(new SubjectRecording( instanceId, name, metadata, InterpolateFilterAndShift(capturedPositions, startTime, endTime, pauseSlices), InterpolateFilterAndShift(capturedRotations, startTime, endTime, pauseSlices), Squash(capturedLifeCycleEvents, startTime, endTime, pauseSlices), CaptureUtil.FilterAndShift(capturedCustomActorEvents, startTime, endTime, pauseSlices))); }
/// <summary> /// キャプチャを実行する /// </summary> internal void ExecuteCapture() { try { string imagePath = CaptureUtil.GetScreenTrimmingImagePath(Screen.PrimaryScreen, Screen.PrimaryScreen.Bounds); if (imagePath != null) { Image img = Image.FromFile(imagePath); ImageList[GetSelectedImageIndex()] = new Bitmap(img); CaptureImage.Image = img; } } catch (Exception ex) { throw Program.ThrowException(ex); } }
/// <summary> /// 範囲座標取得ボタンのクリックイベント /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DetectAreaChoiceButton_Click(object sender, EventArgs e) { try { int[] trimPos = CaptureUtil.GetScreenTrimmingPoint(Screen.PrimaryScreen, Screen.PrimaryScreen.Bounds); if (trimPos != null) { DetectAreaSXTextBox.Text = "" + trimPos[0]; DetectAreaSYTextBox.Text = "" + trimPos[1]; DetectAreaEXTextBox.Text = "" + trimPos[2]; DetectAreaEYTextBox.Text = "" + trimPos[3]; } } catch (Exception ex) { throw Program.ThrowException(ex); } }
/// <summary> /// Stops the recorder and builds a recording for playback. Once a recorder is finished it is free to start making a whole new recording. /// </summary> /// <returns>A recording containing everything the recorder captured while not paused.</returns> /// <exception cref="System.InvalidOperationException">Thrown when the recorder is stopped.</exception> public Recording Finish() { if (CurrentlyStopped()) { throw new System.InvalidOperationException("Not recording anything! Nothing to build!"); } if (CurrentlyPaused()) { Resume(); } currentState = RecordingState.Stopped; var recordings = new SubjectRecording[subjectsToRecord.Count]; for (int i = 0; i < recordings.Length; i++) { recordings[i] = subjectsToRecord[i].Save(timeStarted, Time.time, pauseSlices); } return(Recording.CreateInstance(recordings, CaptureUtil.FilterAndShift(customEvents, timeStarted, Time.time, pauseSlices), metadata)); }