Would you like to react to this message? Create an account in a few clicks or log in to continue.

    RES#ZER.NET

    avatar
    Admin
    Admin


    Posts : 77
    Join date : 2009-07-28

    RES#ZER.NET Empty RES#ZER.NET

    Post  Admin Sun Jan 10, 2010 9:38 am

    RESIZING A PICURE EXAMPLE
    Code:
    public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
    {
       System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

       // Prevent using images internal thumbnail
       FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
       FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

       if (OnlyResizeIfWider)
       {
          if (FullsizeImage.Width <= NewWidth)
          {
             NewWidth = FullsizeImage.Width;
          }
       }

       int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
       if (NewHeight > MaxHeight)
       {
          // Resize with height instead
          NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
          NewHeight = MaxHeight;
       }

       System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

       // Clear handle to original file so that we can overwrite it if necessary
       FullsizeImage.Dispose();

       // Save resized picture
       NewImage.Save(NewFile);
    }

      Current date/time is Fri May 10, 2024 2:14 am