導航:首頁 > 版本升級 > 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保存文件夾相關的資料

熱點內容
qq群里的機器人買武器 瀏覽:428
捕魚達人歷史版本 瀏覽:73
mp4視頻文件解密軟體 瀏覽:62
多軸編程哪個軟體最方便 瀏覽:27
老平板哪個是顯示屏數據線插座 瀏覽:849
5sing上傳音頻文件格式 瀏覽:171
win10輸入文件滑鼠右鍵異常 瀏覽:634
聽幼兒故事用什麼app 瀏覽:514
iphone修改音頻文件名 瀏覽:53
國家氣象站點數據在哪裡下載 瀏覽:342
網路設置的網站 瀏覽:914
手機測量放樣怎麼導數據和線型 瀏覽:648
企業展示型網站源碼 瀏覽:781
易花花app哪裡下載 瀏覽:323
外國程序員職業生涯長 瀏覽:709
看理想app怎麼注銷賬號 瀏覽:545
數控銑床加工手工編程的步驟有哪些 瀏覽:411
uc瀏覽器為什麼很多網站進不了 瀏覽:513
西部數據移動硬碟怎麼 瀏覽:645
批處理修改子目錄文件名命令 瀏覽:405

友情鏈接