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. General Programming
  3. C#
  4. reducing image file size

reducing image file size

Scheduled Pinned Locked Moved C#
graphicshelpquestion
3 Posts 3 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.
  • M Offline
    M Offline
    michael cohen
    wrote on last edited by
    #1

    hey i have a site and i bulid administrator section where he can upload Images to the site. the images sould be on Size 532x301 so im resizing them with this method

          Bitmap b;
          Image i;
          Graphics g;
          b = new Bitmap(width, height);
          i = Image.FromHbitmap(b.GetHbitmap());
          g = Graphics.FromImage(i);
         
          g.DrawImage(img, 0f, 0f, width, height);
          g.Dispose();
          img.Dispose();
          return i;
    

    after the resize the image file size is 0.5 MB (it was 5mb before)... i want to reduct the image file size to (100k -200k) so the site could be faster, also i dont have alot of space on my host... can anyone help me ?

    C L 2 Replies Last reply
    0
    • M michael cohen

      hey i have a site and i bulid administrator section where he can upload Images to the site. the images sould be on Size 532x301 so im resizing them with this method

            Bitmap b;
            Image i;
            Graphics g;
            b = new Bitmap(width, height);
            i = Image.FromHbitmap(b.GetHbitmap());
            g = Graphics.FromImage(i);
           
            g.DrawImage(img, 0f, 0f, width, height);
            g.Dispose();
            img.Dispose();
            return i;
      

      after the resize the image file size is 0.5 MB (it was 5mb before)... i want to reduct the image file size to (100k -200k) so the site could be faster, also i dont have alot of space on my host... can anyone help me ?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      michael@cohen wrote:

      b = new Bitmap(width, height); i = Image.FromHbitmap(b.GetHbitmap()); g = Graphics.FromImage(i);

      How utterly bizarre. This is a waste of time. You can call Graphics.FromImage on a Bitmap, in fact, because of bugs in .NET, even if you create an Image, a Bitmap is created. You should use using blocks to auto dispose where you can. If you want images to be smaller, try saving them as jpeg or another compressed format. Otherwise, they are the size of the number of pixels x 3, you can't change that.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • M michael cohen

        hey i have a site and i bulid administrator section where he can upload Images to the site. the images sould be on Size 532x301 so im resizing them with this method

              Bitmap b;
              Image i;
              Graphics g;
              b = new Bitmap(width, height);
              i = Image.FromHbitmap(b.GetHbitmap());
              g = Graphics.FromImage(i);
             
              g.DrawImage(img, 0f, 0f, width, height);
              g.Dispose();
              img.Dispose();
              return i;
        

        after the resize the image file size is 0.5 MB (it was 5mb before)... i want to reduct the image file size to (100k -200k) so the site could be faster, also i dont have alot of space on my host... can anyone help me ?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, your code could be simplified to a single constructor, see new Bitmap(Image, Size), however that would lead to the same result. As Christian said, the smallest file will be obtained by saving it in a format that applies compression, so use JPEG for it. :)

        Luc Pattyn


        Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.


        Local announcement (Antwerp region): Lange Wapper? Neen!


        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