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. Change values of pixels in an area?

Change values of pixels in an area?

Scheduled Pinned Locked Moved C#
question
10 Posts 5 Posters 1 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.
  • G Offline
    G Offline
    gigahertz205
    wrote on last edited by
    #1

    How would i go about changing values in pixels in an area? Note, all pixels will have the same value. I was thinking of using unsafe code to visit every single pixel in that area, but that may be too slow if i do this multiple time.

    V M L 5 Replies Last reply
    0
    • G gigahertz205

      How would i go about changing values in pixels in an area? Note, all pixels will have the same value. I was thinking of using unsafe code to visit every single pixel in that area, but that may be too slow if i do this multiple time.

      V Offline
      V Offline
      vikas amin
      wrote on last edited by
      #2

      YOU CAN USE SetPixel() Bitmap bitmap = new Bitmap(@"C://1.bmp"); Color newColor = Color.FromArgb(0, 0,100); bitmap.SetPixel(i, j, newColor);

      Vikas Amin

      My First Article on CP" Virtual Serial Port "[^]

      modified on Thursday, July 24, 2008 5:33 PM

      1 Reply Last reply
      0
      • G gigahertz205

        How would i go about changing values in pixels in an area? Note, all pixels will have the same value. I was thinking of using unsafe code to visit every single pixel in that area, but that may be too slow if i do this multiple time.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        What's an "area"? Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        L 1 Reply Last reply
        0
        • G gigahertz205

          How would i go about changing values in pixels in an area? Note, all pixels will have the same value. I was thinking of using unsafe code to visit every single pixel in that area, but that may be too slow if i do this multiple time.

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

          You have two "easy" options: * http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fillrectangle.aspx[^] * directly accessing the pixels via an unmanaged pointer in an unsafe block I suggest you try both methods and see which one is faster. The fastest approach would probably be to set up a DirectX graphics device and render the area using a custom pixel shader. Depending on your needs this might be a bit overkill, though. regards

          G 1 Reply Last reply
          0
          • M Mark Salsbery

            What's an "area"? Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            Mark Salsbery wrote:

            What's an "area"?

            This could qualify[^]

            led mike

            M 1 Reply Last reply
            0
            • L led mike

              Mark Salsbery wrote:

              What's an "area"?

              This could qualify[^]

              led mike

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              That's IT! I'm going to lunch!

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • L Lost User

                You have two "easy" options: * http://msdn.microsoft.com/en-us/library/system.drawing.graphics.fillrectangle.aspx[^] * directly accessing the pixels via an unmanaged pointer in an unsafe block I suggest you try both methods and see which one is faster. The fastest approach would probably be to set up a DirectX graphics device and render the area using a custom pixel shader. Depending on your needs this might be a bit overkill, though. regards

                G Offline
                G Offline
                gigahertz205
                wrote on last edited by
                #7

                I set a specific value of intensity (for greyscale) or color within that region so fillrectangle is out of the question. So i guess unsafe is the way to go. As far as DirectX goes, I have no idea how to set it up. To answer the question above, an "area" is considered a portion of an image. Hence an area or region.

                M 1 Reply Last reply
                0
                • G gigahertz205

                  I set a specific value of intensity (for greyscale) or color within that region so fillrectangle is out of the question. So i guess unsafe is the way to go. As far as DirectX goes, I have no idea how to set it up. To answer the question above, an "area" is considered a portion of an image. Hence an area or region.

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  Can you express this area as a Region (System.Drawing)? If so can you create a Region from the image and use Graphics.FillRegion()?

                  gigahertz205 wrote:

                  I set a specific value of intensity (for greyscale) or color within that region so fillrectangle is out of the question.

                  What do you mean by that? Your original post stated all the pixels in the area will be the same color. You can use any color brush you want to with FillRectangle() :confused: Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  • G gigahertz205

                    How would i go about changing values in pixels in an area? Note, all pixels will have the same value. I was thinking of using unsafe code to visit every single pixel in that area, but that may be too slow if i do this multiple time.

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

                    1.creat a new bitmap (with new color) 2.put the new bitmap on you want area using GDI+

                    1 Reply Last reply
                    0
                    • G gigahertz205

                      How would i go about changing values in pixels in an area? Note, all pixels will have the same value. I was thinking of using unsafe code to visit every single pixel in that area, but that may be too slow if i do this multiple time.

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

                      u can make a new bitmap with u want color and put it on your want change area using GDI+

                      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