码迷,mamicode.com
首页 > Windows程序 > 详细

2014.2.23 datagridview显示图片的方法

时间:2016-10-15 19:52:28      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

DataTable dt = new DataTable();

dt.Columns.Add("", typeof(byte[]));      

dt.Rows.Add(File.ReadAllBytes("F:\\宝宝照片\\2009-04\\P1010591.jpg"));           

du.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

du.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

du.AllowUserToAddRows = false; du.DataSource = dt;

private void dv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)

{

     if (e.ColumnIndex == 0)

    {

        try

        {

            using (MemoryStream oldms = new MemoryStream((byte[])e.Value))

            {

                Image img = Image.FromStream(oldms);

                Bitmap bt = new Bitmap(img, new Size(400, 300));

                using (MemoryStream newms = new MemoryStream())

                {

                    bt.Save(newms, System.Drawing.Imaging.ImageFormat.Jpeg);

                    e.Value = newms.ToArray();

                }

            }

        }

        catch { }

    }

2014.2.23 datagridview显示图片的方法

标签:

原文地址:http://www.cnblogs.com/mol1995/p/5965033.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!