public Bitmap getscreenfromactivewindow()
{
int handle = apitmp.GetForegroundWindow();
return getscreenfromhandle(handle);
}
//保存成各种格式
public string savepic(Bitmap bmp)
{
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.Filter = "位图文件 (*.bmp)|*.bmp|jpg文件 (*.jpg)|*.jpg|gif文件 (*.gif)|*.gif|tiff文件 (*.tiff)|*.tiff|"+
"emf
saveDialog.DefaultExt="*.bmp";
if(saveDialog.ShowDialog() == DialogResult.OK)
{
string ext = saveDialog.FileName.Substring(saveDialog.FileName.Length-4,4);
switch( ext)
{
case ".bmp":
bmp.Save(saveDialog.FileName,ImageFormat.Bmp);
break;
case ".gif":
bmp.Save(saveDialog.FileName,ImageFormat.Gif);
break;
case ".jpg":
bmp.Save(saveDialog.FileName,ImageFormat.Jpeg);
break;
case ".emf":
bmp.Save(saveDialog.FileName,ImageFormat.Emf);
break;
case ".ico":
bmp.Save(saveDialog.FileName,ImageFormat.Icon);
break;
case ".wmf":
bmp.Save(saveDialog.FileName,ImageFormat.Wmf);
break;
case ".png":
bmp.Save(saveDialog.FileName,ImageFormat.Png);
break;
case ".tiff":
bmp.Save(saveDialog.FileName,ImageFormat.Tiff);
break;
default :
return "";
}
return saveDialog.FileName;
}
return "";
}
}
}