看板 C_Sharp 關於我們 聯絡資訊
本來的迴圈,可以不會出錯 foreach (PictureBox p_pb in flowLayoutPanel1.Controls) { byte[] buf; MemoryStream ms = new MemoryStream(); p_pb.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); buf = ms.GetBuffer(); l_cp.產品編號 = lv_strGetMaxPrID l_cp.照片 = buf; ClsPicturesFactory l_cpifactory = new ClsPicturesFactory(); l_cpifactory.create(l_cp); } 改用WPF的控制項,就會出現GDI+ 泛型錯誤 foreach (ElementHost p_eh in flowLayoutPanel1.Controls) { byte[] buf; PictureBox p = new PictureBox(); var source = ((System.Windows.Controls.Image)((UserControl1)p_eh.Child).FindName("Image2")) .Source; p.Load(source.ToString()); MemoryStream ms = new MemoryStream(); p.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);//這行會出錯 buf = ms.GetBuffer(); l_cp.產品編號 = lv_strGetMaxPrID; l_cp.照片 = buf; ClsPicturesFactory l_cpifactory = new ClsPicturesFactory(); l_cpifactory.create(l_cp); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.32.9.209 ※ 編輯: ONLYSMART 來自: 114.32.9.209 (06/07 18:09)
optimist9266:你的source.ToString()應該不是你想像中的圖片檔名稱 06/07 18:36
optimist9266:我記得Image控制項會把你給他的文字檔路徑解碼成 06/07 18:36
optimist9266:ImageSource執行個體 06/07 18:36
大大!請問要則麼改?那個是檔案路徑沒錯!監看式有跑出來! ※ 編輯: ONLYSMART 來自: 114.32.9.209 (06/07 18:46) ※ 編輯: ONLYSMART 來自: 114.32.9.209 (06/07 19:42)