| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 571 人关注过本帖
标题:c#问题 关于缩略图
只看楼主 加入收藏
open382000
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2012-6-29
结帖率:0
收藏
 问题点数:0 回复次数:0 
c#问题 关于缩略图
   private Bitmap CreatSmallPicView(string path)
        {
            //取得原圖
            Bitmap myBitmap = new Bitmap(path);
            //產生一張與imagelist大小的Bitmap
            Bitmap newBmp = new Bitmap(90, 90);
            Graphics g = Graphics.FromImage(newBmp);
            Pen p = new Pen(Color.Goldenrod);
            //設定高品質插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            //設定高品質,低速度呈現平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            //縮圖的寬高
            int newWidth = 0;
            int newHeight = 0;

            //在畫布內重繪縮圖的x,y軸座標
            int startX = 0;
            int startY = 0;

            //90為imagelist大圖示的寬,高
            if (myBitmap.Width > 90 || myBitmap.Height > 90)
            {
                if (myBitmap.Width > myBitmap.Height)
                {
                    //指定寬,高按比例
                    newWidth = 90;
                    newHeight = myBitmap.Height * newWidth / myBitmap.Width;
                    startY = (90 - newHeight) / 2;

                }
                else if (myBitmap.Width < myBitmap.Height)
                {
                    //指定高,寬按比例
                    newHeight = 90;
                    newWidth = myBitmap.Width * newHeight / myBitmap.Height;
                    startX = (90 - newWidth) / 2;
                }
            }
            else
            {
                //保持原圖的大小
                newWidth = myBitmap.Width;
                newHeight = myBitmap.Height;
                startX = (90 - newWidth) / 2;
                startY = (90 - newHeight) / 2;
            }
            //在90*90的畫布中裡在繪出比例縮圖
            g.DrawImage(myBitmap.GetThumbnailImage(newWidth, newHeight,
                null, IntPtr.Zero), startX, startY, newWidth, newHeight);
            //畫出最外圍的方框
            g.DrawRectangle(p, 0, 0, 89, 89);
            g.Dispose();
            myBitmap.Dispose();
            return newBmp;
        }



        private void LoadFile(string path)
        {
            listView.Items.Clear();
            if (Directory.Exists(path) == false) return;
 
         
            DirectoryInfo dirInfo = new DirectoryInfo(path);

            fileImage.ColorDepth = ColorDepth.Depth32Bit;
            listView.LargeImageList = fileImage;
            listView.LargeImageList.ImageSize = new Size(88, 64);
            
         
                  
            FileInfo[] fi = dirInfo.GetFiles("*.jpg");
            foreach (FileInfo file in fi)
            {
            
                ListViewItem item = new ListViewItem();
           
   
                Image img = CreatSmallPicView(path);
                fileImage.Images.Add(img);
      

                item.Text = Path.GetFileNameWithoutExtension(file.FullName);
                item.ImageIndex = fileImage.Images.Count - 1;
                item.Tag = file.FullName;
                listView.Items.Add(item);           
            }         
        }

代码 如上 为什么 我还是实现不了 缩略图 功能呢~我就是想点击treeview 然后在listview上实现遍历里面的图片~
搜索更多相关主题的帖子: 缩略图 private 
2012-08-16 13:07
快速回复:c#问题 关于缩略图
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016695 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved