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. Working with different image format

Working with different image format

Scheduled Pinned Locked Moved C#
graphicsquestionperformancehelp
3 Posts 2 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.
  • S Offline
    S Offline
    Stephane David
    wrote on last edited by
    #1

    In my application, I want to read images which are in the PNG format, 256 colors, with transparency, store them in memory and then display them on screen. So I do something like that : Bitmap[,] myBitmapArray; ... myBitmapArray[i,j] = new Bitmap ("FileName.png"); ... graphics.DrawImage(myBitmapArray[i,j]); The pb is my application takes 100 Mb in memory to load the pictures, which are only 4 Mb in the files :mad: Apparently, when loading a picture, there is no format specifier. So I thought it should use the file, but when looking at the PixelFormat member, it's always 32bpp... So I have tried to create the bitmap another way, like new Bitmap (128,64, System.Drawing.Imaging.PixelFormat.PixelFormat8bppIndexed), and then copy my image from the file here. But : - If I use 16bpp555, I lose the transparency - If I use 16bpp1555, JIT debugging tells me "out of memory" - If I use 8bppIndexed, JIT debugging tells me I cannot create a graphics (graphics.FromImage -> error). How can I load my 256 color files and draw them in a picture box, without taking so much memory because they are transformed in true color?

    P S 2 Replies Last reply
    0
    • S Stephane David

      In my application, I want to read images which are in the PNG format, 256 colors, with transparency, store them in memory and then display them on screen. So I do something like that : Bitmap[,] myBitmapArray; ... myBitmapArray[i,j] = new Bitmap ("FileName.png"); ... graphics.DrawImage(myBitmapArray[i,j]); The pb is my application takes 100 Mb in memory to load the pictures, which are only 4 Mb in the files :mad: Apparently, when loading a picture, there is no format specifier. So I thought it should use the file, but when looking at the PixelFormat member, it's always 32bpp... So I have tried to create the bitmap another way, like new Bitmap (128,64, System.Drawing.Imaging.PixelFormat.PixelFormat8bppIndexed), and then copy my image from the file here. But : - If I use 16bpp555, I lose the transparency - If I use 16bpp1555, JIT debugging tells me "out of memory" - If I use 8bppIndexed, JIT debugging tells me I cannot create a graphics (graphics.FromImage -> error). How can I load my 256 color files and draw them in a picture box, without taking so much memory because they are transformed in true color?

      P Offline
      P Offline
      Philip Fitzsimons
      wrote on last edited by
      #2

      i think you mean Format16bppArgb1555? you could hack it an store the byte[] data from the image in an array, and then only create the bitmap when you need it..


      "When the only tool you have is a hammer, a sore thumb you will have."

      1 Reply Last reply
      0
      • S Stephane David

        In my application, I want to read images which are in the PNG format, 256 colors, with transparency, store them in memory and then display them on screen. So I do something like that : Bitmap[,] myBitmapArray; ... myBitmapArray[i,j] = new Bitmap ("FileName.png"); ... graphics.DrawImage(myBitmapArray[i,j]); The pb is my application takes 100 Mb in memory to load the pictures, which are only 4 Mb in the files :mad: Apparently, when loading a picture, there is no format specifier. So I thought it should use the file, but when looking at the PixelFormat member, it's always 32bpp... So I have tried to create the bitmap another way, like new Bitmap (128,64, System.Drawing.Imaging.PixelFormat.PixelFormat8bppIndexed), and then copy my image from the file here. But : - If I use 16bpp555, I lose the transparency - If I use 16bpp1555, JIT debugging tells me "out of memory" - If I use 8bppIndexed, JIT debugging tells me I cannot create a graphics (graphics.FromImage -> error). How can I load my 256 color files and draw them in a picture box, without taking so much memory because they are transformed in true color?

        S Offline
        S Offline
        Stephane David
        wrote on last edited by
        #3

        I've made some further testing, and discovered it comes from the format. With two similar picture, 256 colors,one is png the other is gif Bitmap bitmap = new Bitmap("Myfile.png"); -> bitmap.PixelFormat = PixelFormat.Format32bppArgb Bitmap bitmap = new Bitmap("Myfile.gif"); -> bitmap.PixelFormat = PixelFormat.Format8bppIndexed Conclusion : The png codec is "buggy" and if you use the standard constructor, the bitmap ignore the file attributes and is always 32bppp. The gif coded works OK, and the bitmap keeps the file attributes. With this, I've reduced my application memory usage by 60%

        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