C# - 비트맵을 이미지 화일로 저장
Aforge를 사용한 웹캠 사진 캡쳐
=================================================================================
private void start_Click(object sender, EventArgs e)
{
if (start.Text == "&Start")
{
if (DeviceExist)
{
videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
CloseVideoSource();
videoSource.DesiredFrameSize = new Size(160, 120);
//videoSource.DesiredFrameRate = 10;
videoSource.Start();
label2.Text = "Device running...";
start.Text = "&Stop";
timer1.Enabled = true;
}
else
{
label2.Text = "Error: No Device selected.";
}
}
else
{
if (videoSource.IsRunning)
{
timer1.Enabled = false;
CloseVideoSource();
label2.Text = "Device stopped.";
start.Text = "&Start";
}
}
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = img;
}
private void btnCapture_Click(object sender, EventArgs e)
{
//Bitmap img = new Bitmap(240, 180);
Bitmap img = new Bitmap(pictureBox1.Image);
string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
img.Save(filename, ImageFormat.Jpeg);
img.Dispose();
}
=================================================================================
Image.Save 메서드 (String, ImageFormat)
http://msdn.microsoft.com/ko-kr/library/9t4syfhh(v=vs.80).aspx
private void ConstructFromResourceSaveAsGif(PaintEventArgs e) { // Construct a bitmap from the button image resource. Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp"); // Save the image as a GIF. bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif); // Construct a new image from the GIF file. Bitmap bmp2 = new Bitmap("c:\\button.gif"); // Draw the two images. e.Graphics.DrawImage(bmp1, new Point(10, 10)); e.Graphics.DrawImage(bmp2, new Point(10, 40)); // Dispose of the image files. bmp1.Dispose(); bmp2.Dispose(); }
http://pino93.tistory.com/entry/C-Control%EC%9D%84-Image%EB%A1%9C-%EC%A0%80%EC%9E%A5
1 Bitmap bmp = new Bitmap(this.panel.Width, this.panel.Height);
2 this.panel.DrawToBitmap(bmp, new Rectangle(0, 0, this.panel.Width, this.panel.Height));
3 bmp.Save("panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);