以下两种方法都可以实现你的需求
- #region 设置 picture1.DataField
- System.Drawing.Image imgfile = System.Drawing.Image.FromFile("D:\images\");
- System.IO.MemoryStream stream = new System.IO.MemoryStream();
- imgfile.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
- picture1.Image = System.Drawing.Image.FromStream(stream);
- byte[] imageBinary = new byte[stream.Length];
- stream.Position = 0;
- stream.Read(imageBinary, 0, (int)stream.Length);
- DataTable dt = new DataTable();
- dt.Columns.Add("Image", typeof(System.Byte[]));
- dt.Columns.Add("OtherCol", typeof(string));
- dt.Rows.Add(new object[] { imageBinary, "111" });
- this.DataSource = dt;
- picture1.DataField = "Image";
- #endregion
- #region 设置 picture1.Image
- picture1.Image = System.Drawing.Image.FromFile("D:\images\");
- #endregion
复制代码 |