1. 程式人生 > >(C#)WPF儲存圖片,將圖片提交到服務端進行儲存

(C#)WPF儲存圖片,將圖片提交到服務端進行儲存

1、服務端程式碼  private string DocumentFlowSwitchPath(byte[][] byteTuPian)     {         try         {             //按照年月日時分秒組成一個字串             string strFilePrefix = DateTime.Now.Year.ToString() +                                   DateTime.Now.Month.ToString() +                                   DateTime
.Now.Day.ToString() + 
                                  DateTime.Now.Hour.ToString() +                                   DateTime.Now.Minute.ToString() +                                    DateTime.Now.Second.ToString() +                                   DateTime.Now.Millisecond.ToString();             //圖片名稱變數
            string strFileName = "";             for (int i = 0; i < byteTuPian.Length; i++)//遍歷二進位制的陣列的陣列             {                 string strRiQiWenJian = strFilePrefix + i.ToString() + ".png";                 //獲取根目錄磁碟路徑                 string strBaoCunLuJing = System.AppDomain.CurrentDomain.BaseDirectory;
                strBaoCunLuJing = strBaoCunLuJing + "image\\" + strRiQiWenJian;                 FileInfo fi = new System.IO.FileInfo(strBaoCunLuJing);                 FileStream fs;                 fs = fi.OpenWrite();                 fs.Write(byteTuPian[i], 0, byteTuPian[i].Length);                 fs.Close();                 strFileName += strRiQiWenJian;             }             return strFileName;         }         catch         {             return null;         }     }  
2、頁面設計   3、。cs介面程式碼
 //宣告一個byte[]型別的集合 List<byte[]> lstBytes1 = new List<byte[]>();  //點選儲存進行員工資訊的儲存     private void btnUpdate_Click(object sender, RoutedEventArgs e)     {             byte[][] HeadPhoto = new byte[lstBytes1.Count][];             for (int i = 0; i < lstBytes1.Count; i++)             {                 HeadPhoto[i] = lstBytes1[i];             }                            DataTable dt = bll_Emloyee.DocumentFlowSwitchPath(HeadPhoto).Tables[0];             }       //點選選擇頭像按鈕事件,單開檔案     private void btn_openFile_Click(object sender, RoutedEventArgs e)     {         Stream checkStream = null;         Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();         openFileDialog.Multiselect = false;         openFileDialog.Filter = "All Image Files | *.*";         if ((bool)openFileDialog.ShowDialog())         {             lstBytes1.Clear();             if ((checkStream = openFileDialog.OpenFile()) != null)             {                 int Length = (int)checkStream.Length;                 byte[] bytes = new byte[Length];  //二進位制檔案存放的二進位制陣列                 checkStream.Read(bytes, 0, Length);                 lstBytes1.Add(bytes);                 scrolls.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute)).Clone();                    }         }     }