Thumbnail Image : Image : Graphics C# Source Code


Custom Search

C# Source Code » Graphics » Image »

 

Thumbnail Image








    
 

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);
          }
     }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Graphics
» Image