using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using OpenNETCF.Drawing;
namespace Screen
{
public partial class Form1 : Form
{
private string systemPath;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Image image = new Bitmap(480, 640);
Graphics g = Graphics.FromImage(image);
GraphicsEx gex = GraphicsEx.FromGraphics(g);
gex.CopyFromScreen(0,0, 0,0, new Size(480, 640));
pictureBox1.Image = image;
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = " bmp file (*.bmp)|*.bmp|jpg file (*.jpg)| *.jpg| gif file(*.gif)|*.gif |png file(*.png)|*.png";
dlg.FilterIndex = 2;
string fileName;
if (dlg.ShowDialog() == DialogResult.OK)
{
fileName = dlg.FileName;
fileName = fileName + Getextension(dlg.FilterIndex);
}
else
{
return;
}
//string fileName = System.IO.Path.Combine(systemPath, "1.png");
image.Save(fileName, GetFormat(dlg.FilterIndex));
//image.Save(fileName, ImageFormat.Png);
}
catch (Exception ex)
{
MessageBox.Show("保存出错:" + ex.StackTrace.ToString());
}
}
/// <summary>
/// 获取扩展名
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public string Getextension(int i)
{
switch (i)
{
case 1: return ".bmp";
case 2: return ".jpg";
case 3: return ".gif";
case 4: return ".png";
default: return ".bmp";
}
}
public ImageFormat GetFormat(int i)
{
switch (i)
{
case 1: return ImageFormat.Bmp;
case 2: return ImageFormat.Jpeg;
case 3: return ImageFormat.Gif;
case 4: return ImageFormat.Png;
default: return ImageFormat.Bmp;
}
}
}
}