public partial class Form10 : Form
{
public Form10()
{
InitializeComponent();
}
private void Form10_Load(object sender, EventArgs e)
{
ImageList imageList = new ImageList();
imageList.ImageSize = new Size(108, 108);
imageList.ColorDepth = ColorDepth.Depth32Bit;
string[] pathes = new string[] { "*****i need to give OPEN DIALOGBOX PATH TO HERE"*******};
foreach (string path in pathes)
{
Image img1 = Image.FromFile(path);
imageList.Images.Add(getThumbnaiImage(imageList.ImageSize.Width, img1));
}
for (int j = 0; j < pathes.Length; j++)
{
this.listView1.Items.Add("Image\n aaaaaa\r\n bbbbbbbbbbbbbbbbbbbbb ");
this.listView1.Items[j].ImageIndex = j;
}
this.listView1.View = View.LargeIcon;
this.listView1.LargeImageList = imageList;
}
private Image getThumbnaiImage(int width, Image img)
{
Image thumb = new Bitmap(width, width);
Image tmp = null;
//If the original image is small than the Thumbnail size, just draw in the center
if (img.Width < width && img.Height < width)
{
using (Graphics g = Graphics.FromImage(thumb))
{
int xoffset = (int)((width - img.Width) / 2);
int yoffset = (int)((width - img.Height) / 2);
g.DrawImage(img, xoffset, yoffset, img.Width, img.Height);
}
}
else //Otherwise we have to get the thumbnail for drawing
{
Image.GetThumbnailImageAbort myCallback = new
Image.GetThumbnailImageAbort(ThumbnailCallback);
if (img.Width == img.Height)
{
thumb = img.GetThumbnailImage(
width, width,
myCallback, IntPtr.Zero);
}
else
{
int k = 0;
int xoffset = 0;
int yoffset = 0;
if (img.Width < img.Height)
{
k = (int)(width * img.Width / img.Height);
tmp = img.GetThumbnailImage(k, width, myCallback, IntPtr.Zero);
xoffset = (int)((width - k) / 2);
}
if (img.Width > img.Height)
{
k = (int)(width * img.Height / img.Width);
tmp = img.GetThumbnailImage(width, k, myCallback, IntPtr.Zero);
yoffset = (int)((width - k) / 2);
}
using (Graphics g = Graphics.FromImage(thumb))
{
g.DrawImage(tmp, xoffset, yoffset, tmp.Width, tmp.Height);
}
}
}
using (Graphics g = Graphics.FromImage(thumb))
{
g.DrawRectangle(Pens.Green, 0, 0, thumb.Width - 1, thumb.Height - 1);
}
return thumb;
}
public bool ThumbnailCallback()
{
return true;
}
}