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. 16bit grayscale png export? (and import?)

16bit grayscale png export? (and import?)

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpquestioncsharpc++visual-studio
12 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.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    Hopefully this forum is appropriate for this question. No one seems to visit the graphics forum very often. I need to be able to both import and export a 16 bit grayscale png file. I have found some help with importing but exporting is a big problem. I have found stack overflow references to Magick.NET but I cannot get this source to compile in VS 2012 as it requires build tools 141 and setting it to 110 results in errors, one of which is a missing dll that I cannot find using internet resources. I have already tried installing runtimes for later versions and for some reason they cannot be used. Probably because I use Windows 7. Are there any other alternatives? Or advice on how to get a runtime of Magick.NET? I need to be able to read, manipulate (on an individual basis), and save 16 bit grayscale pixel values to a heightmap for importing into various terrain editors. In terms of manipulating, I can probably use the native 48 bit rgb pixel format (please correct me if I am wrong) for display, convert, and then just read/write to the image directly but I still need to find a runtime that supports reading and writing to the 16 bit format. It would be nice however, if there was a library that did this automatically.

    L Richard DeemingR 4 Replies Last reply
    0
    • P primem0ver

      Hopefully this forum is appropriate for this question. No one seems to visit the graphics forum very often. I need to be able to both import and export a 16 bit grayscale png file. I have found some help with importing but exporting is a big problem. I have found stack overflow references to Magick.NET but I cannot get this source to compile in VS 2012 as it requires build tools 141 and setting it to 110 results in errors, one of which is a missing dll that I cannot find using internet resources. I have already tried installing runtimes for later versions and for some reason they cannot be used. Probably because I use Windows 7. Are there any other alternatives? Or advice on how to get a runtime of Magick.NET? I need to be able to read, manipulate (on an individual basis), and save 16 bit grayscale pixel values to a heightmap for importing into various terrain editors. In terms of manipulating, I can probably use the native 48 bit rgb pixel format (please correct me if I am wrong) for display, convert, and then just read/write to the image directly but I still need to find a runtime that supports reading and writing to the 16 bit format. It would be nice however, if there was a library that did this automatically.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Try the GIMP API: gimpconvert gimpconvert — Conversions between RGB, indexed, and grayscale modes. [gimpconvert](https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpconvert.html)

      "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

      P 1 Reply Last reply
      0
      • L Lost User

        Try the GIMP API: gimpconvert gimpconvert — Conversions between RGB, indexed, and grayscale modes. [gimpconvert](https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpconvert.html)

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        P Offline
        P Offline
        primem0ver
        wrote on last edited by
        #3

        Thanks for your quick reply. That looks like a native library. Not necessarily a problem but I am curious if there is a .NET wrapper. Also, is that a dll separate from the software or will I need to run GIMP? Is there any documentation on the class formats and uses? I am noticing things like "image_id" and other proprietary data types. One problem I may run into is that I currently need a 64 bit library as my project requires enough memory to produce extremely large bitmaps for illustrating data (I need around 2,061,341,604 bytes available for a 22701 x 22701 image in addition to the regular memory used by the application which is not small by itself).

        L 1 Reply Last reply
        0
        • P primem0ver

          Thanks for your quick reply. That looks like a native library. Not necessarily a problem but I am curious if there is a .NET wrapper. Also, is that a dll separate from the software or will I need to run GIMP? Is there any documentation on the class formats and uses? I am noticing things like "image_id" and other proprietary data types. One problem I may run into is that I currently need a 64 bit library as my project requires enough memory to produce extremely large bitmaps for illustrating data (I need around 2,061,341,604 bytes available for a 22701 x 22701 image in addition to the regular memory used by the application which is not small by itself).

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I've used the app; not the API. One way to "automate" GIMP is "scripting". I think there's also a wrapper out there. You have options ... and research. One interfaces with native DLL's when one needs to. OLE. Type libraries. etc. POV-Ray would be my next look ... more scripting. Paint.NET ?

          "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

          1 Reply Last reply
          0
          • P primem0ver

            Hopefully this forum is appropriate for this question. No one seems to visit the graphics forum very often. I need to be able to both import and export a 16 bit grayscale png file. I have found some help with importing but exporting is a big problem. I have found stack overflow references to Magick.NET but I cannot get this source to compile in VS 2012 as it requires build tools 141 and setting it to 110 results in errors, one of which is a missing dll that I cannot find using internet resources. I have already tried installing runtimes for later versions and for some reason they cannot be used. Probably because I use Windows 7. Are there any other alternatives? Or advice on how to get a runtime of Magick.NET? I need to be able to read, manipulate (on an individual basis), and save 16 bit grayscale pixel values to a heightmap for importing into various terrain editors. In terms of manipulating, I can probably use the native 48 bit rgb pixel format (please correct me if I am wrong) for display, convert, and then just read/write to the image directly but I still need to find a runtime that supports reading and writing to the 16 bit format. It would be nice however, if there was a library that did this automatically.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            If you save a bitmap with a png extension, you get a png file. Grayscaling will be described as a tip/trick or article. --edit ..and you can load a png file into a bitmap. Give it a try :)

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            P 1 Reply Last reply
            0
            • L Lost User

              If you save a bitmap with a png extension, you get a png file. Grayscaling will be described as a tip/trick or article. --edit ..and you can load a png file into a bitmap. Give it a try :)

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

              P Offline
              P Offline
              primem0ver
              wrote on last edited by
              #6

              Yes... been doing what you describe for years. However GDI+ does not import 16 bit greyscale as a 16 bit grayscale and does not export 16 bit grayscale. When it imports, it imports as a 32bit bgra which makes dealing with 16 bit grayscale values impossible because of the loss of information when converting 16 bit grayscale values to 8 bit rgb values. Exporting through the standard .NET drawing libraries is impossible as I have already read in several posts on this topic. My application needs to use grayscale values from 0-65535 in order to avoid a "shelved" appearance in the heightmaps I generate.

              L 1 Reply Last reply
              0
              • P primem0ver

                Hopefully this forum is appropriate for this question. No one seems to visit the graphics forum very often. I need to be able to both import and export a 16 bit grayscale png file. I have found some help with importing but exporting is a big problem. I have found stack overflow references to Magick.NET but I cannot get this source to compile in VS 2012 as it requires build tools 141 and setting it to 110 results in errors, one of which is a missing dll that I cannot find using internet resources. I have already tried installing runtimes for later versions and for some reason they cannot be used. Probably because I use Windows 7. Are there any other alternatives? Or advice on how to get a runtime of Magick.NET? I need to be able to read, manipulate (on an individual basis), and save 16 bit grayscale pixel values to a heightmap for importing into various terrain editors. In terms of manipulating, I can probably use the native 48 bit rgb pixel format (please correct me if I am wrong) for display, convert, and then just read/write to the image directly but I still need to find a runtime that supports reading and writing to the 16 bit format. It would be nice however, if there was a library that did this automatically.

                Richard DeemingR Offline
                Richard DeemingR Offline
                Richard Deeming
                wrote on last edited by
                #7

                If GDI+ doesn't support the format, then there's nothing you can do with the System.Drawing assembly. There are other libraries available, which might support the format. For example:

                • Magick.NET[^]
                • SkiaSharp[^]

                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                P 1 Reply Last reply
                0
                • P primem0ver

                  Yes... been doing what you describe for years. However GDI+ does not import 16 bit greyscale as a 16 bit grayscale and does not export 16 bit grayscale. When it imports, it imports as a 32bit bgra which makes dealing with 16 bit grayscale values impossible because of the loss of information when converting 16 bit grayscale values to 8 bit rgb values. Exporting through the standard .NET drawing libraries is impossible as I have already read in several posts on this topic. My application needs to use grayscale values from 0-65535 in order to avoid a "shelved" appearance in the heightmaps I generate.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  "ARGB" would be four bytes, RGB three. 65635 should fit easily into a 32bit value, without loss.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  P 1 Reply Last reply
                  0
                  • L Lost User

                    "ARGB" would be four bytes, RGB three. 65635 should fit easily into a 32bit value, without loss.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                    P Offline
                    P Offline
                    primem0ver
                    wrote on last edited by
                    #9

                    Hmm... well it appears that either you don't understand colorspaces and how color values work, or you didn't realize that I am trying to display the picture while working on it (which to me is a given). Doing what you suggest will not produce a grayscale picture as assigning a pixel in ARGB format the value of 65535 will give the G (green) channel a value of 255 and a blue channel value of 255 (making yellow) and an ARGB pixel value of 255 will give solid blue. Furthermore, when .NET reads a 16bit grayscale picture, it DOES use the ARGB (specifically the 32bbpARGB) format and it DOES loose the data because it truncates the 16 bit value to an 8 bit value, losing the less significant bits (so 65535 is read as 255 and 255 is read as zero). You can find documentation about this issue all over the internet. It has the same effect as dividing the 16 bit values by 256. It then fills each of the color channels (RGB) with this 8 bit value so that they are all the same, giving a grayscale picture. Otherwise, you would not see a grayscale picture. If you then try to save the file, it will result in an 8bit grayscale picture. If you try using the 16bbpGrayscale pixel format and then try to save it, .NET throws an exception because 16 bit grayscale picture loading and saving are not supported by .NET (hence the need for this thread).

                    L 1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      If GDI+ doesn't support the format, then there's nothing you can do with the System.Drawing assembly. There are other libraries available, which might support the format. For example:

                      • Magick.NET[^]
                      • SkiaSharp[^]

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      P Offline
                      P Offline
                      primem0ver
                      wrote on last edited by
                      #10

                      Thanks. I hadn't heard of SkiaSharp. I will look into them. I mentioned my problem with Magick.NET in the OP but it turns out that the link for the runtime is just hard to find. Apparently I don't have to compile Magick.NET myself (which I was unable to do because their format is for VS 2017... they don't have any downloads for earlier versions of VS). As is, I have a working solution since I found the Magick.NET dll and while inefficient, I have a work-around. To clarify, I will probably still look into SkiaSharp for this, or future reference, as Magick.NET doesn't appear to have an efficient way of modifying pixel values directly.

                      1 Reply Last reply
                      0
                      • P primem0ver

                        Hopefully this forum is appropriate for this question. No one seems to visit the graphics forum very often. I need to be able to both import and export a 16 bit grayscale png file. I have found some help with importing but exporting is a big problem. I have found stack overflow references to Magick.NET but I cannot get this source to compile in VS 2012 as it requires build tools 141 and setting it to 110 results in errors, one of which is a missing dll that I cannot find using internet resources. I have already tried installing runtimes for later versions and for some reason they cannot be used. Probably because I use Windows 7. Are there any other alternatives? Or advice on how to get a runtime of Magick.NET? I need to be able to read, manipulate (on an individual basis), and save 16 bit grayscale pixel values to a heightmap for importing into various terrain editors. In terms of manipulating, I can probably use the native 48 bit rgb pixel format (please correct me if I am wrong) for display, convert, and then just read/write to the image directly but I still need to find a runtime that supports reading and writing to the 16 bit format. It would be nice however, if there was a library that did this automatically.

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Here's another source; lots of filters; converters; etc. [IrfanView - Official Homepage - One of the Most Popular Viewers Worldwide](http://www.irfanview.com/)

                        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

                        1 Reply Last reply
                        0
                        • P primem0ver

                          Hmm... well it appears that either you don't understand colorspaces and how color values work, or you didn't realize that I am trying to display the picture while working on it (which to me is a given). Doing what you suggest will not produce a grayscale picture as assigning a pixel in ARGB format the value of 65535 will give the G (green) channel a value of 255 and a blue channel value of 255 (making yellow) and an ARGB pixel value of 255 will give solid blue. Furthermore, when .NET reads a 16bit grayscale picture, it DOES use the ARGB (specifically the 32bbpARGB) format and it DOES loose the data because it truncates the 16 bit value to an 8 bit value, losing the less significant bits (so 65535 is read as 255 and 255 is read as zero). You can find documentation about this issue all over the internet. It has the same effect as dividing the 16 bit values by 256. It then fills each of the color channels (RGB) with this 8 bit value so that they are all the same, giving a grayscale picture. Otherwise, you would not see a grayscale picture. If you then try to save the file, it will result in an 8bit grayscale picture. If you try using the 16bbpGrayscale pixel format and then try to save it, .NET throws an exception because 16 bit grayscale picture loading and saving are not supported by .NET (hence the need for this thread).

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          primem0ver wrote:

                          Hmm... well it appears that either you don't understand colorspaces and how color values work, or you didn't realize that I am trying to display the picture while working on it (which to me is a given).

                          Not much experience with manipulating the colormap, just curious :)

                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                          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