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