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. Bitmap file size

Bitmap file size

Scheduled Pinned Locked Moved C#
csharpgraphicsquestion
6 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.
  • D Offline
    D Offline
    DannyAdler
    wrote on last edited by
    #1

    Hi all, Is there a way for checking the file size of a Bitmap without saving it to disk (using C#)? Thanks in advance, Danny

    V 1 Reply Last reply
    0
    • D DannyAdler

      Hi all, Is there a way for checking the file size of a Bitmap without saving it to disk (using C#)? Thanks in advance, Danny

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Wouldn't using a Temp File be more cleaner approach?

      Vasudevan Deepak Kumar Personal Homepage
      Tech Gossips
      A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

      D 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        Wouldn't using a Temp File be more cleaner approach?

        Vasudevan Deepak Kumar Personal Homepage
        Tech Gossips
        A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

        D Offline
        D Offline
        DannyAdler
        wrote on last edited by
        #3

        Vasudevan Deepak K wrote:

        Wouldn't using a Temp File be more cleaner approach?

        Thanks for you quick response. Yes it would, BUT, I'm trying to limit a Bitmap to a certain file size, say 50kb, so my solution was to loop through the bitmap's dimmensions, while each iteration is scaling the bitmap down. Now, inside this loop, using IO-write to the disk would be pretty slow... Any other idea? Danny

        L 1 Reply Last reply
        0
        • D DannyAdler

          Vasudevan Deepak K wrote:

          Wouldn't using a Temp File be more cleaner approach?

          Thanks for you quick response. Yes it would, BUT, I'm trying to limit a Bitmap to a certain file size, say 50kb, so my solution was to loop through the bitmap's dimmensions, while each iteration is scaling the bitmap down. Now, inside this loop, using IO-write to the disk would be pretty slow... Any other idea? Danny

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

          Hi, some suggestions: 1. you could save in a memory stream and get its size 2. you could do a binary search, example: if original width is 128 try 64; if too small, try (128+64)/2 = 96, else try (0+64)/2=32; repeat until you reach the optimal size. 3. the file size depends on the image format; some use compression, some don't. for the ones that don't, the size is proportional to width*height; for those that use compression, this is also true to some extent. 4. when scaling down the size, for best quality I suggest you always restart from the original image. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Sorry for any delays in replying, I currently don't always get e-mail notifications.


          D 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, some suggestions: 1. you could save in a memory stream and get its size 2. you could do a binary search, example: if original width is 128 try 64; if too small, try (128+64)/2 = 96, else try (0+64)/2=32; repeat until you reach the optimal size. 3. the file size depends on the image format; some use compression, some don't. for the ones that don't, the size is proportional to width*height; for those that use compression, this is also true to some extent. 4. when scaling down the size, for best quality I suggest you always restart from the original image. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Sorry for any delays in replying, I currently don't always get e-mail notifications.


            D Offline
            D Offline
            DannyAdler
            wrote on last edited by
            #5

            Hey Luc, I figured I can use a memory stream, that was my first try, before posting in this forum, but now I got it to work, I didn't understand the use of the ImageFormat, and now I do. #4 is a great idea, and I've implemented it. Thanks man. Danny

            L 1 Reply Last reply
            0
            • D DannyAdler

              Hey Luc, I figured I can use a memory stream, that was my first try, before posting in this forum, but now I got it to work, I didn't understand the use of the ImageFormat, and now I do. #4 is a great idea, and I've implemented it. Thanks man. Danny

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

              You're welcome.

              Luc Pattyn [Forum Guidelines] [My Articles]


              Sorry for any delays in replying, I currently don't always get e-mail notifications.


              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