화면의 일부를 캡처하여 확대/축소하는 화면 확대/축소 기능을 만들고 싶습니다. 아래 코드는 이제 화면을 캡처하여 PictureBox에서 재생할 수 있습니다. 그러나 나는 프로그램을 여는 동안 내 기억이 계속 자라나는이 문제를 안고있다. 나는 공개되지 않은 자원이 있어야한다고 나는 그것을 풀어 놓는 방법을 모른다.PictureBox 리소스 릴리스
저는 미디어 플레이어처럼 보이게 만들고 있지만 비디오를 재생하는 대신 현재 화면의 일부를 재생합니다.
public partial class Form1 : Form
{
PictureBox picBox;
Bitmap bit;
Graphics g;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
picBox = pictureBox;
}
private void CopyScreen()
{
bit = new Bitmap(this.Width, this.Height);
g = Graphics.FromImage(bit as Image);
Point upperLeftSource = new Point(
Screen.PrimaryScreen.Bounds.Width/2 - this.Width/2,
Screen.PrimaryScreen.Bounds.Height/2 - this.Height/2);
g.CopyFromScreen(upperLeftSource, new Point(0, 0), bit.Size);
picBox.Image = Image.FromHbitmap(bit.GetHbitmap());
bit.Dispose();
g.Dispose();
}
private void timer_Tick(object sender, EventArgs e)
{
CopyScreen();
}
https://stackoverflow.com/questions/1831732/c-sharp-picturebox-memory-releasing-problem –
@mjwills에서 작동합니다 ... 메모리가 계속 성장합니다. –
@mjwills 타이머 간격을 설정했습니다. ~ 20 정도로 초당 10MB와 같이 메모리가 매우 빠르게 증가합니다. –