Create a Thumbnail in C#

try

{

    // Create an Image object from a file.

    // PhotoTextBox.Text is the full path of your image

    using (Image photoImg = Image.FromFile(PhotoTextBox.Text))

    {

        // Create a Thumbnail from image with size 50x40.

        // Change 50 and 40 with whatever size you want

        using (Image thumbPhoto = photoImg.GetThumbnailImage(50, 40, null, new System.IntPtr()))

        {

            // The below code converts an Image object to a byte array

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())

            {

                thumbPhoto.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

                imgBytes = ms.ToArray();

            }

        }

    }

}

catch (Exception exp)

{

    MessageBox.Show("Select a valid photo!");

    PhotoTextBox.Select();

    return;

}        

 



Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.