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. Resize a monochrome bitmap without using any class

Resize a monochrome bitmap without using any class

Scheduled Pinned Locked Moved .NET (Core and Framework)
graphicsquestionwinforms
7 Posts 4 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

    Dear Friends. I want to resize a monochrome bitmap (every pixel can only contains 0 or 1) to another size (like 32*32 to 30*50). I can do it with GDI+ but I want to do it WITHOUT USING ANY CLASS LIKE GDI+. (only loop , for , if , etc.) How can I do it?

    Regards. Mehdi Ghiasi

    L T 2 Replies Last reply
    0
    • M Mehdi Ghiasi

      Dear Friends. I want to resize a monochrome bitmap (every pixel can only contains 0 or 1) to another size (like 32*32 to 30*50). I can do it with GDI+ but I want to do it WITHOUT USING ANY CLASS LIKE GDI+. (only loop , for , if , etc.) How can I do it?

      Regards. Mehdi Ghiasi

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

      You can't run anything under .NET without using some .NET classes, so I'll assume the classes you want to avoid are the graphical ones only. Then this is the recipe:

      1. study the specification of your input image format, maybe it is a BMP file;
      2. read the input, probably into a byte array;
      3. now turn it into some in-memory representation that you feel comfortable with;
      4. perform the resize, i.e. create a new bitmap in memory
      5. study the specification of your output image format, maybe it is a PNG file;
      6. generate your output image by converting it into the output format.

      You probably could combine some of the steps. You will need a lot of bit manipulations, so make sure you are fluent in masking, shifting, and the like. For the resizing itself, you may choose a nearest-neighbor approach, or alternatively you may want to study different interpolation algorithms, bi-cubic is popular. If you need an extra challenge, you may implement compression, e.g. the one used in the JPEG file format. The alternative to all of the above is less than 10 lines of code, based on the Bitmap class. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      I only read formatted code with indentation, so please use PRE tags for code snippets.


      I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


      M 1 Reply Last reply
      0
      • L Luc Pattyn

        You can't run anything under .NET without using some .NET classes, so I'll assume the classes you want to avoid are the graphical ones only. Then this is the recipe:

        1. study the specification of your input image format, maybe it is a BMP file;
        2. read the input, probably into a byte array;
        3. now turn it into some in-memory representation that you feel comfortable with;
        4. perform the resize, i.e. create a new bitmap in memory
        5. study the specification of your output image format, maybe it is a PNG file;
        6. generate your output image by converting it into the output format.

        You probably could combine some of the steps. You will need a lot of bit manipulations, so make sure you are fluent in masking, shifting, and the like. For the resizing itself, you may choose a nearest-neighbor approach, or alternatively you may want to study different interpolation algorithms, bi-cubic is popular. If you need an extra challenge, you may implement compression, e.g. the one used in the JPEG file format. The alternative to all of the above is less than 10 lines of code, based on the Bitmap class. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read formatted code with indentation, so please use PRE tags for code snippets.


        I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


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

        No! I have a monochrome bitmap in an integer array table and I want to resize it into a new array WITHOUT GDI+ or any Class that Resizes the image For me. I want to know How It Works!

        Regards. Mehdi Ghiasi

        L 1 Reply Last reply
        0
        • M Mehdi Ghiasi

          No! I have a monochrome bitmap in an integer array table and I want to resize it into a new array WITHOUT GDI+ or any Class that Resizes the image For me. I want to know How It Works!

          Regards. Mehdi Ghiasi

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

          The result probably won't look very good under these conditions; here are two examples (data in binary): 1. an image with a width of 8 pixels, one row containing

          00101110

          scaled up by a factor of 2, it becomes

          0000110011111100
          0000110011111100

          So the result is a "pixelated" image, bits just got replicated, as there is no extra information available. 2. the reverse operation: an image with a width of 16 pixels, two rows containing

          0x0x1x0x1x1x1x0x
          xxxxxxxxxxxxxxxx

          (you can put a 0 or 1 at any of the 'x' positions) scaled down by a factor of 2 it could become

          00101110

          which again does not look anywhere near the same as the original as 75% of the information got thrown away. And that was only the very simple case of a scale by 1/2 or 2/1. As I said before, you will need a lot of bit manipulations, so make sure you are fluent in masking, shifting, and the like. For the resizing itself, you may choose a nearest-neighbor approach. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read formatted code with indentation, so please use PRE tags for code snippets.


          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


          M 1 Reply Last reply
          0
          • L Luc Pattyn

            The result probably won't look very good under these conditions; here are two examples (data in binary): 1. an image with a width of 8 pixels, one row containing

            00101110

            scaled up by a factor of 2, it becomes

            0000110011111100
            0000110011111100

            So the result is a "pixelated" image, bits just got replicated, as there is no extra information available. 2. the reverse operation: an image with a width of 16 pixels, two rows containing

            0x0x1x0x1x1x1x0x
            xxxxxxxxxxxxxxxx

            (you can put a 0 or 1 at any of the 'x' positions) scaled down by a factor of 2 it could become

            00101110

            which again does not look anywhere near the same as the original as 75% of the information got thrown away. And that was only the very simple case of a scale by 1/2 or 2/1. As I said before, you will need a lot of bit manipulations, so make sure you are fluent in masking, shifting, and the like. For the resizing itself, you may choose a nearest-neighbor approach. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read formatted code with indentation, so please use PRE tags for code snippets.


            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


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

            So how can I scale a 100x100 image into 150x150 ?

            Regards. Mehdi Ghiasi

            T 1 Reply Last reply
            0
            • M Mehdi Ghiasi

              So how can I scale a 100x100 image into 150x150 ?

              Regards. Mehdi Ghiasi

              T Offline
              T Offline
              Thomas Krojer
              wrote on last edited by
              #6

              only double even OR odd bits ...

              1 Reply Last reply
              0
              • M Mehdi Ghiasi

                Dear Friends. I want to resize a monochrome bitmap (every pixel can only contains 0 or 1) to another size (like 32*32 to 30*50). I can do it with GDI+ but I want to do it WITHOUT USING ANY CLASS LIKE GDI+. (only loop , for , if , etc.) How can I do it?

                Regards. Mehdi Ghiasi

                T Offline
                T Offline
                T M Gray
                wrote on last edited by
                #7

                I want to answer you, but I want to do it without using any words or code. If you get my telepathic message you should be all set.

                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