SIGN UP MEMBER LOGIN:    
ARTICLE

Create Image Thumbnails in C#

Posted by Mahesh Chand Articles | GDI+ & Graphics June 10, 2010
The code snippet and project attached in this article demonstrates how to create a control that displays thumbnails of images using GDI+ and C#.
Reader Level:
Download Files:
 

The code for Browse Multiple Files button click event handler looks like following that let users select multiple images and show their thumbnails. Download the attached project for more details. The application looks like this:

thumbnailImg.jpg

It is is a Windows Forms application developed using Visual Studio 2010.

private void BrowseMultipleButton_Click(object sender, EventArgs e)

{

        this.openFileDialog1.Filter =

        "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" +

        "All files (*.*)|*.*";

 

    this.openFileDialog1.Multiselect = true;

    this.openFileDialog1.Title = "Select Photos";

 

        DialogResult dr = this.openFileDialog1.ShowDialog();

        if (dr == System.Windows.Forms.DialogResult.OK)

        {

            foreach (String file in openFileDialog1.FileNames)

            {

                try

                {

                    PictureBox imageControl = new PictureBox();

                    imageControl.Height = 100;

                    imageControl.Width = 100;

 

                    Image.GetThumbnailImageAbort myCallback =

                            new Image.GetThumbnailImageAbort(ThumbnailCallback);

                    Bitmap myBitmap = new Bitmap(file);

                    Image myThumbnail = myBitmap.GetThumbnailImage(96, 96,

                        myCallback, IntPtr.Zero);

                    imageControl.Image = myThumbnail;

 

                    PhotoGallary.Controls.Add(imageControl);

                }

                catch (Exception ex)

                {

                    MessageBox.Show("Error: " + ex.Message);

                }

            }

        }

}

 

public bool ThumbnailCallback()

{

    return false;

}

Login to add your contents and source code to this article
share this article :
post comment
 

Search this site for Access data connection. There are some articles on this topic.

Posted by Mahesh Chand Nov 08, 2010

Do you have an option to buid same in WPF? WPF Image control can have events.

Posted by Mahesh Chand Nov 08, 2010

Dear Sir,

Kindly give example for MS Access 2007 attachment data type  in C# 2005.

Safeer (safeerkt@gmail.com)

Posted by Safeer Karippathodika Nov 01, 2010

Hi,

i want click event on the images. please let me know


Thanks,
Farhan.

Posted by Veera pandiyan Sep 22, 2010

if i click a image, how to display full view.

Regards,
Veerapandiayn.K

Posted by Veera pandiyan Sep 22, 2010
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor