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. .NET (Core and Framework)
  4. Load image problem

Load image problem

Scheduled Pinned Locked Moved .NET (Core and Framework)
questiongraphicshelpannouncement
5 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
    Mehdi Ghiasi
    wrote on last edited by
    #1

    Hello, I want to load an JPEG image from file to a picturebox. I know that i can load using :

    Picturebox1.image = image.fromfile("D:\MyImage.jpg")

    and

    dim b as new bitmap("D:\MyImage.jpg")
    Picturebox1.image = b

    but when I loading image using these ways, it loads bitmap format and uses more RAM space. (e.g a 3MB JPEG file uses 40MB RAM after loading) How Can I load the file with low RAM usage? UPDATE : Microsoft Paint also use 40MB RAM After open that file, but Microsoft Photo viewer use very low RAM usage. How can I load images with low RAM usage????? :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:

    Regards. Mehdi Ghiasi

    D L 2 Replies Last reply
    0
    • M Mehdi Ghiasi

      Hello, I want to load an JPEG image from file to a picturebox. I know that i can load using :

      Picturebox1.image = image.fromfile("D:\MyImage.jpg")

      and

      dim b as new bitmap("D:\MyImage.jpg")
      Picturebox1.image = b

      but when I loading image using these ways, it loads bitmap format and uses more RAM space. (e.g a 3MB JPEG file uses 40MB RAM after loading) How Can I load the file with low RAM usage? UPDATE : Microsoft Paint also use 40MB RAM After open that file, but Microsoft Photo viewer use very low RAM usage. How can I load images with low RAM usage????? :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:

      Regards. Mehdi Ghiasi

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You can't. THe image is represented in memory as a 32-bit full resolution bitmap in memory. In the file, it's compressed down to whatever the JPEG encoding settings are. For example, an image that is 3000x2000 pixels will take up 24MB of memory at full resolution. The resulting image on screen will not be that large, so it'll get painted scaled down to whatever size is visible. There is no class in the .NET Framework that will reduce the memory size by representing the image in its file format. You'd have to either write your own class to do this or find a 3rd party library that does this. I don't know of any.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • M Mehdi Ghiasi

        Hello, I want to load an JPEG image from file to a picturebox. I know that i can load using :

        Picturebox1.image = image.fromfile("D:\MyImage.jpg")

        and

        dim b as new bitmap("D:\MyImage.jpg")
        Picturebox1.image = b

        but when I loading image using these ways, it loads bitmap format and uses more RAM space. (e.g a 3MB JPEG file uses 40MB RAM after loading) How Can I load the file with low RAM usage? UPDATE : Microsoft Paint also use 40MB RAM After open that file, but Microsoft Photo viewer use very low RAM usage. How can I load images with low RAM usage????? :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:

        Regards. Mehdi Ghiasi

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

        if, I repeat: if, your PictureBox is significantly smaller than the original image, then you could solve your problem by creating a new and smaller image, like so:

        Bitmap bm1=Bitmap.FromFile(filespec);
        Bitmap bm2=new Bitmap(bm1, myPictureBox.Size);
        bm1.Dispose();
        myPictureBox.Image=bm2;

        if not, there's nothing much you can do about it, as .NET keeps images in RAM as real bitmaps (normally 4B/px). :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        M 1 Reply Last reply
        0
        • L Luc Pattyn

          if, I repeat: if, your PictureBox is significantly smaller than the original image, then you could solve your problem by creating a new and smaller image, like so:

          Bitmap bm1=Bitmap.FromFile(filespec);
          Bitmap bm2=new Bitmap(bm1, myPictureBox.Size);
          bm1.Dispose();
          myPictureBox.Image=bm2;

          if not, there's nothing much you can do about it, as .NET keeps images in RAM as real bitmaps (normally 4B/px). :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          M Offline
          M Offline
          Mehdi Ghiasi
          wrote on last edited by
          #4

          So, How Microsoft Photo viewer uses a little memory using full loading picture ? (it can zoom into picture with full quality) :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused: also delphi can load images as jpeg! Thanks for your answer.

          Regards. Mehdi Ghiasi

          modified on Friday, September 3, 2010 9:29 PM

          D 1 Reply Last reply
          0
          • M Mehdi Ghiasi

            So, How Microsoft Photo viewer uses a little memory using full loading picture ? (it can zoom into picture with full quality) :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused: also delphi can load images as jpeg! Thanks for your answer.

            Regards. Mehdi Ghiasi

            modified on Friday, September 3, 2010 9:29 PM

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Probably because it implemented a custom class to represent the image in its native file format in memory. That would also mean it has to have custom rendering code to parse the image data, as needed, and only the sections of it that are required to render the visible part of the image on screen.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            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