Resize a picture when uploading

Discussion in 'ASP.NET / ASP.NET Core' started by Frank42, Jan 30, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Im using asp.net with vb script and I was wondering if there is a way to resize a picture automaticaly before it gets uploaded. Or have the server automaticaly resize it after its uploaded.

    Thanks in Advance
     
  2. I am trying to change the height and width of the images. Say from 1024x768 pixels to 800x600 pixels.
    I have the upload working fine. Just need to resize the jpg.
    Where do I set the image elements height and width attributes?
     
  3. Hi,

    Do you mean image deimensions (ie height and width)? Or actual file size (ie size on disk)?

    If the former then this is easily accomplished by setting the image elements height and width attributes.

    If the latter, this should be possible. However, you would have to write a custom application to accomplish it. This would make an excellent web-service, though you may find that it is more trouble than it is worth.

    Hope this helps.

    Dave
     
  4. quote:... if there is a way to resize a picture automaticaly before it gets uploaded</blockquote id="quote"></font id="quote">

    That would mean that the resizing has to be done on the client side. As far as I know, that is not possible using javascript or vbscript. I will probably be possible using Java-applet, but then you should seek some help elsewhere.

    quote: ... or have the server automaticaly resize it after its uploaded</blockquote id="quote"></font id="quote">

    Using components as AspImage that is possible I believe. You can set the maximum size of the images that you want to store on the server.

    Success !

    --
    Steurm
    www.steurm.net/steurm
     
  5. I see you change the size the image is displayed as , but it leaves the actual file at the origional size. Well for now I will write a small vb program to do it on the clients computer and look into building an excellent web-service to do it in the future. Thanks for the posts.
     
  6. Height and width can be specified as attributes of the img html element.

    e.g. <img width='800px' height='600px' src='myImage.gif' >

    This will force an image of any size to fit the dimensions 800 by 600 pixels. Hope this helps.

    Dave
     
  7. Sorry, I didn't realise you actually had to resize the image. I thought you just wanted to display at a certain size. Have a look at the System.Drawing namespace. The code below should give you a starting point:

    <code>
    //Create a new Image object with the existing jpeg
    System.Drawing.Image img = System.Drawing.Image.FromFile(Path to image file here);

    //Create a new Bitmap object, specifying height and width required for the new image
    System.Drawing.Bitmap bmp = new Bitmap(img, 800, 600);

    // Save the new image to whatever location you require
    bmp.Save(@"C:\newImage.jpeg");
    </code>

    You may have to do a little more work than this to get exactly what you are after (for instance you may want to use one of the Save methods Overloads that takes ImageCodecInfo and EncoderParameters), but it should be a good starting point and is actually not as difficult as I first imagined.

    Good luck.

    Dave
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page