스트리밍

 

컴퓨터에 나오는 화면을 캡처하여 프로그램에 나타내는 프로그램이다.

 

원리는 간단하다.

1. 0.1초마다 사진을 찍듯 캡쳐를 한다.

2. WinForm의 Picture box에 띄워준다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        Size sz;
        Bitmap bitmap;
        Graphics graphics;
        Thread thread;
        MemoryStream ms;
        byte[] buf;
 
        public Form1()
        {
            InitializeComponent();
 
            graphics = Graphics.FromImage(bitmap);
            thread = new Thread(Capture_Thread);
            ms = new MemoryStream();
        }
 
        public void Capture_Thread()
        {
            while (true)
            {
                graphics.CopyFromScreen(0000, sz);
 
                try
                {
                    bitmap.Save("x2.jpg"ImageFormat.Jpeg);
                    bitmap.Save(ms, ImageFormat.Jpeg);
                    buf = ms.ToArray();
                }
                catch(Exception e)
                {
                    MessageBox.Show(e.StackTrace);
                }
 
                pictureBox1.ImageLocation = "x2.jpg";
                Thread.Sleep(100);
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (!thread.IsAlive)
            thread.Start();
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

최종 목표는 이미지를 Byte로 변환하여 TCP 통신하는 것이다.

그리고 현 상태의 문제점은 초당 10 프레임이라는 것.

+ Recent posts