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. Total Posts: 1 Member Since: Jan 30, 2006 [C#] loading .pgm file within a Bitmap object

Total Posts: 1 Member Since: Jan 30, 2006 [C#] loading .pgm file within a Bitmap object

Scheduled Pinned Locked Moved C#
csharpgraphicshelphtml
5 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.
  • L Offline
    L Offline
    Lawx01
    wrote on last edited by
    #1

    Hi everyone, freshly arrived in the System.Drawing namespace , I try to figure out how it works. But for this precise problem, I need your help: I am trying to load an image in a Bitmap object. The source file is a .pgm grayscale image (format specifications: http://netpbm.sourceforge.net/doc/pgm.html) I don't know if there already exists some method from a class that can help me convert the data or if I should write something on my own. In this last case, I really lack some idea. As always, it would not be fun if I was not in a hurry, let's say that my project is turning into an emergency. Any help is welcome Thx Law

    C 1 Reply Last reply
    0
    • L Lawx01

      Hi everyone, freshly arrived in the System.Drawing namespace , I try to figure out how it works. But for this precise problem, I need your help: I am trying to load an image in a Bitmap object. The source file is a .pgm grayscale image (format specifications: http://netpbm.sourceforge.net/doc/pgm.html) I don't know if there already exists some method from a class that can help me convert the data or if I should write something on my own. In this last case, I really lack some idea. As always, it would not be fun if I was not in a hurry, let's say that my project is turning into an emergency. Any help is welcome Thx Law

      C Offline
      C Offline
      CiNN
      wrote on last edited by
      #2

      write in a memory stream the bmp header and decode the pgm data to the stream and load the stream as a bitmap and voila.

      L 1 Reply Last reply
      0
      • C CiNN

        write in a memory stream the bmp header and decode the pgm data to the stream and load the stream as a bitmap and voila.

        L Offline
        L Offline
        Lawx01
        wrote on last edited by
        #3

        Thank you for your help. I just like to insist on the beginner aspect of my question. Could you be a more precise? I don't think I need the bmp header, I just want to use the System.Drawing.Bitmap class. Also, the decoding phase from pgm to bitmap is a bit confusing for me. What PixelFormat should I use for the receiving bitmap? Is the conversion from a single int to a pixel is okay? grayValue = br.ReadByte(); pixel = Convert.ToInt32(grayValue); bmp.SetPixel(i, j, Color.FromArgb(pixel,pixel,pixel) Thanks Law

        C 1 Reply Last reply
        0
        • L Lawx01

          Thank you for your help. I just like to insist on the beginner aspect of my question. Could you be a more precise? I don't think I need the bmp header, I just want to use the System.Drawing.Bitmap class. Also, the decoding phase from pgm to bitmap is a bit confusing for me. What PixelFormat should I use for the receiving bitmap? Is the conversion from a single int to a pixel is okay? grayValue = br.ReadByte(); pixel = Convert.ToInt32(grayValue); bmp.SetPixel(i, j, Color.FromArgb(pixel,pixel,pixel) Thanks Law

          C Offline
          C Offline
          CiNN
          wrote on last edited by
          #4

          you forgot to scale the grayvalue # Each gray value is a number proportional to the intensity of the pixel, adjusted by the ITU-R Recommendation BT.709 gamma transfer function. (That transfer function specifies a gamma number of 2.2 and has a linear section for small intensities). A value of zero is therefore black. A value of Maxval represents CIE D65 white and the most intense value in the image and any other image to which the image might be compared. in the exemple 15 so pixel =(int)((grayValue *255)/15); PixelFormat should be the default Canonical # Each gray value is represented in pure binary by either 1 or 2 bytes. If the Maxval is less than 256, it is 1 byte. Otherwise, it is 2 bytes. The most significant byte is first. so you need to do either a readbyte or readuint16

          L 1 Reply Last reply
          0
          • C CiNN

            you forgot to scale the grayvalue # Each gray value is a number proportional to the intensity of the pixel, adjusted by the ITU-R Recommendation BT.709 gamma transfer function. (That transfer function specifies a gamma number of 2.2 and has a linear section for small intensities). A value of zero is therefore black. A value of Maxval represents CIE D65 white and the most intense value in the image and any other image to which the image might be compared. in the exemple 15 so pixel =(int)((grayValue *255)/15); PixelFormat should be the default Canonical # Each gray value is represented in pure binary by either 1 or 2 bytes. If the Maxval is less than 256, it is 1 byte. Otherwise, it is 2 bytes. The most significant byte is first. so you need to do either a readbyte or readuint16

            L Offline
            L Offline
            Lawx01
            wrote on last edited by
            #5

            Tank you, but even when scaling, I still have some troubles. I can not understand why. But the good news is that I have found a library for .NET languages that opens many type of image files. It's called DEvIL.NET and can be found at: http://www.mastropaolo.com/?page\_id=20 This solution is easy to set up an works pretty fast. Thank you for your help CiNN Law

            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