Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to restrict the size of image at the time of upload

How to restrict the size of image at the time of upload

Scheduled Pinned Locked Moved ASP.NET
helptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    narendrakumarp
    wrote on last edited by
    #1

    Hi I need to restrict the size of image at the time of uploading. So please tell me the suggestion. Thanking u, Naren

    please help me

    B 1 Reply Last reply
    0
    • N narendrakumarp

      Hi I need to restrict the size of image at the time of uploading. So please tell me the suggestion. Thanking u, Naren

      please help me

      B Offline
      B Offline
      Britney S Morales
      wrote on last edited by
      #2

      You could find you answers at Chris Khoo post http://www.codeproject.com/aspnet/netimageupload.asp Based in that post i made these two functions for asp.net C#. you must to invoice the public function. The parameters are: MaxWidth = max Width pixels MaxHeight = max height pixels UrlAndFileName = the From address image UrlAndNewFileName = the save address and new file name Example: (600, 600, "C:\Documents and Settings\Barriosj.FMMB\Mis documentos\Mis imágenes\imagenes\73237_4611.jpg", "c:/myRedimImage.jpg") The image is restricted by the smallest width or heigth value. public void Redim_And_SaveImg(int MaxWidth, int MaxHeight, string UrlAndFileName, string UrlAndnewFileName) { // load up the image, figure out a "best fit" // resize, and then save that new image Bitmap OriginalBmp = (System.Drawing.Bitmap)Image.FromFile(UrlAndFileName).Clone(); Size ResizedDimensions = ObtainDim(MaxWidth, MaxHeight, ref OriginalBmp); Bitmap NewBmp = new Bitmap(OriginalBmp, ResizedDimensions); NewBmp.Save(UrlAndnewFileName, System.Drawing.Imaging.ImageFormat.Jpeg); } private static Size ObtainDim(int MaxWidth, int MaxHeight, ref Bitmap Bmp) { int Width; int Height; float Multiplier; Height = Bmp.Height; Width = Bmp.Width; // this means you want to shrink // an image that is already shrunken! if (Height <= MaxHeight && Width <= MaxWidth) return new Size(Width, Height); // check to see if we can shrink it width first Multiplier = (float)((float)MaxWidth / (float)Width); if ((Height * Multiplier) <= MaxHeight) { Height = (int)(Height * Multiplier); return new Size(MaxWidth, Height); } // if we can't get our max width, then use the max height Multiplier = (float)MaxHeight / (float)Height; Width = (int)(Width * Multiplier); return new Size(Width, MaxHeight); } :)

      keep Learning and you never will be out of date...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups