导航:首页 > 版本升级 > cbitmap保存文件夹

cbitmap保存文件夹

发布时间:2023-11-01 09:47:29

1. C#.net中,如何自动保存文件到指定位置

截的图保存到指定的路径例子如下:
try
{
Screen scr = Screen.PrimaryScreen;
Rectangle rc = scr.Bounds;
int iWidth = rc.Width;
int iHeight = rc.Height;
Bitmap myImage = new Bitmap(iWidth, iHeight);
Graphics gl = Graphics.FromImage(myImage);
gl.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
_img = myImage;
pictureBox1.Image = _img;
// IntPtr dc1 = gl.GetHdc();
//gl.ReleaseHdc(dc1);
_img.Save(@"C:\\1.jpeg");
//_img.Save("c:\\1.jpeg");
//SendFile("c:\\1.jpeg");
}
catch (Exception ex)
{
MessageBox.Show("截屏失败!\n" + ex.Message.ToString() + "\n" + ex.StackTrace.ToString());
}
解决代码如下:
#region[方法]
///<summary>
///截屏
///</summary>
private void PrintScreen()
{

string Opath = @"C:/Picture";
if (Opath.Substring(Opath.Length - 1, 1) != @"/")
Opath = Opath + @"/";
string photoname = DateTime.Now.Ticks.ToString();
string path1 = Opath + DateTime.Now.ToShortDateString();
if (!Directory.Exists(path1))
Directory.CreateDirectory(path1);
try
{

Screen scr = Screen.PrimaryScreen;
Rectangle rc = scr.Bounds;
int iWidth = rc.Width;
int iHeight = rc.Height;
Bitmap myImage = new Bitmap(iWidth, iHeight);
Graphics gl = Graphics.FromImage(myImage);
gl.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight));
_img = myImage;
//pictureBox1.Image = _img;
// IntPtr dc1 = gl.GetHdc();
//gl.ReleaseHdc(dc1);
MessageBox.Show(path1);
MessageBox.Show(photoname);
_img.Save(path1 + "//" + photoname + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
// _img.Save("D:\\1.jpeg");
SendFile(path1+"//"+photoname+".jpg");
}
catch (Exception ex)
{
MessageBox.Show("截屏失败!\n" + ex.Message.ToString() + "\n" + ex.StackTrace.ToString());
}

// MessageBox.Show("12322222");
/////////////////////////////////////////////////////////
///////////////////发送图片流///////////////////////////
/*
MemoryStream ms = new MemoryStream();
byte[] imagedata = null;
_img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
imagedata = ms.GetBuffer();

byte[] arrFile = new byte[1024 * 1024 * 2];
//读取文件内容到字节数组,并 获得 实际文件大小
int length = ms.Read(arrFile, 0, arrFile.Length);
// int length = ms.Read(arrFile, 0, arrFile.Length);
//定义一个 新数组,长度为文件实际长度 +1
byte[] arrFileFina = new byte[length + 1];
arrFileFina[0] = 2;//设置 数据标识位等于1,代表 发送的是文件
//将 图片流数据数组 复制到 新数组中,下标从1开始
//arrFile.CopyTo(arrFileFina, 1);
Buffer.BlockCopy(arrFile, 0, arrFileFina, 1, length);
//发送文件数据
sokClient.Send(arrFileFina);//, 0, length + 1, SocketFlags.None);
//MessageBox.Show("我在这里!!!");
// byte[] arrMsg = System.Text.Encoding.UTF8.GetBytes(_img);
MessageBox.Show("2222");
*/
}
#endregion

阅读全文

与cbitmap保存文件夹相关的资料

热点内容
ps打不开pdf文件吗 浏览:735
ipadappleid申请流程 浏览:103
aspx用什么数据库 浏览:520
小米工具文件夹选项在哪里 浏览:75
u盘cad图形文件不能用 浏览:2
照片整理到一个pdf文件里 浏览:735
狂野飙车8安卓内购版 浏览:993
什么是app充值 浏览:678
手机k歌app哪个伴奏音最好 浏览:723
jsalert后跳转 浏览:441
dnf85版本银月pk视频 浏览:428
三菱plc梯形图教程 浏览:433
vb合并pdf文件代码 浏览:237
黎明杀机人类升级 浏览:317
s级宝物定海神针升级要多少药水 浏览:33
iPhone6splus南非版本 浏览:868
有关张国荣的app 浏览:500
奇妙加速器找不到文件 浏览:133
模态框内嵌jsp 浏览:891
桌面文件归类设置 浏览:698

友情链接