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上实现遍历里面的图片~