zoukankan      html  css  js  c++  java
  • 2014.2.23 datagridview显示图片的方法

    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 { }

        }

  • 相关阅读:
    .NET XmlNavigator with Namespace
    编程要素
    【FOJ】1962 新击鼓传花游戏
    【POJ】1389 Area of Simple Polygons
    【POJ】2482 Stars in Your Window
    【HDU】3265 Posters
    【HDU】1199 Color the Ball
    【HDU】3642 Get The Treasury
    【HDU】4027 Can you answer these queries?
    【HDU】1542 Atlantis
  • 原文地址:https://www.cnblogs.com/mol1995/p/5965033.html
Copyright © 2011-2022 走看看