Image.GetThumbnailImage : Image « System.Drawing « C# / C Sharp by API






Image.GetThumbnailImage

 
using System;
using System.Drawing;
using System.Windows.Forms;
   
class Thumbnail: Form
{
     const int iSquare = 64;
     Image imageThumbnail;
   
     public static void Main()
     {
          Application.Run(new Thumbnail());
     }
     public Thumbnail()
     {
          Text = "Thumbnail";
          ResizeRedraw = true; 
          Image image = Image.FromFile("Color.jpg");
   
          int cxThumbnail, cyThumbnail;
   
          if (image.Width > image.Height)
          {
               cxThumbnail = iSquare;
               cyThumbnail = iSquare * image.Height / image.Width;
          }
          else
          {
               cyThumbnail = iSquare;
               cxThumbnail = iSquare * image.Width / image.Height;
          }
          imageThumbnail = image.GetThumbnailImage(cxThumbnail, cyThumbnail,
                                                   null, (IntPtr) 0);
     }
     protected override void OnPaint(PaintEventArgs pea)
     {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }      
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
     {
          for (int y = 0; y < cy; y += iSquare){
              for (int x = 0; x < cx; x += iSquare)
                   grfx.DrawImage(imageThumbnail, 
                                  x + (iSquare - imageThumbnail.Width) / 2,
                                  y + (iSquare - imageThumbnail.Height) / 2,
                                  imageThumbnail.Width, imageThumbnail.Height);
          }
     }
}

   
  








Related examples in the same category

1.Image.FromFile(String path)
2.Image.FromStream
3.Image.Height
4.Image.VerticalResolution
5.Image.RotateFlip(RotateFlipType.Rotate180FlipY)