Resizing Images and getting a black background and larger file size

Discussion in 'ASP .Net' started by Ron Vecchi, Oct 16, 2003.

  1. Ron Vecchi

    Ron Vecchi Guest

    I am using asp.net to upload an image and then perform resizing on it and
    saving the different sizes to file.
    The resized images were coming up and being displayed in the bowser fine but
    the image sizes are a lot bigger(in file size) than the actual image being
    uploaded.
    The actual image being uploaded was around 22000bytes
    The smaller resized image is 120000bytes

    Also on the web when the resized image is displayed it starts out with a
    black background and progressivly shows the image


    I also downloaded some of the resized images and tried opening them in
    photoshop and I got an error saying it couldn't open them because of an
    unknown jpeg marker.
    I posted my code for resizing the image below, mabey I went about it wrong.
    Any ideas



    -------------------------------------------------------

    this.CreateSpecialRotator(ImageName,"SpecialProducts",180,180);



    private void CreateSpecialRotator(string ImageName,string DirectoryName,int
    Width, int Height)
    {
    if(! System.IO.Directory.Exists(this.ImageUploadDirectoryPath + "\\" +
    DirectoryName))
    {
    System.IO.Directory.CreateDirectory(this.ImageUploadDirectoryPath +
    "\\" + DirectoryName);
    }

    if(File.Exists(this.ImageUploadDirectoryPath + "\\" + ImageName))
    {
    System.Drawing.Image i =
    System.Drawing.Image.FromFile(this.ImageUploadDirectoryPath + "\\" +
    ImageName);
    System.Drawing.Bitmap ThumbNail;

    if(i.Width > 180)
    {
    ThumbNail = new
    Bitmap(i,180,this.CalculateHeight(i.Height,i.Width,180));
    }
    else
    {
    ThumbNail = new Bitmap(i);
    }
    ThumbNail.Save(this.ImageUploadDirectoryPath + "\\" + DirectoryName
    + "\\" + ImageName);
    i.Dispose();
    ThumbNail.Dispose();
    }
    }

    Thanks,
    Ron Vecchi
     
    Ron Vecchi, Oct 16, 2003
    #1
    1. Advertising

  2. Ron Vecchi

    MSFT Guest

    Hi Ron,

    You may try to sepcify the image's format property when saving it, for
    exmaple:

    ThumbNail.Save("c:\test\result.jpg",
    System.Drawing.Imaging.ImageFormat.Jpeg);

    Based on my test, the result jpg file will be smaller than source file with
    above code.

    Hope this help,

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    MSFT, Oct 17, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonas
    Replies:
    1
    Views:
    3,305
    Daniel Fisher\(lennybacon\)
    Aug 12, 2005
  2. Peter Williams
    Replies:
    1
    Views:
    1,457
    Dylan Parry
    Jun 3, 2005
  3. Replies:
    0
    Views:
    1,760
  4. zou
    Replies:
    3
    Views:
    586
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
    Sep 30, 2007
  5. zou
    Replies:
    12
    Views:
    691
    Richard
    Sep 30, 2007
Loading...

Share This Page