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. Changing Colors

Changing Colors

Scheduled Pinned Locked Moved C#
graphicsarchitecturetutorialquestion
6 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.
  • G Offline
    G Offline
    Greeky
    wrote on last edited by
    #1

    For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()

    J R I 3 Replies Last reply
    0
    • G Greeky

      For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()

      J Offline
      J Offline
      jeyapandian
      wrote on last edited by
      #2

      hi, i think there is no direct method to accompolish this with C#.you have to use API like bitblt and compare the colors and change.. you can try with GDI/Graphic section...There is a lot of samples i found last time. good luck Where there is a will,there is a way.

      1 Reply Last reply
      0
      • G Greeky

        For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        Hi, a simple way would be to load it as a Bitmap and to iterate over every pixel and use the GetPixel/setPixel functions on the bitmap to change pixel by pixel. As those calls are rather slow you could also go the unmanaged way. Have a look at Image Processing for Dummies by Christian Graus[^] for further details on this.

        G 1 Reply Last reply
        0
        • R Robert Rohde

          Hi, a simple way would be to load it as a Bitmap and to iterate over every pixel and use the GetPixel/setPixel functions on the bitmap to change pixel by pixel. As those calls are rather slow you could also go the unmanaged way. Have a look at Image Processing for Dummies by Christian Graus[^] for further details on this.

          G Offline
          G Offline
          Greeky
          wrote on last edited by
          #4

          thank you I found this sample so GetPixel and SetPixel is ok for me. My new question is my picture box is set to Strech view. My image's width =768 , height=503 but on secreen, rightbottom corner pixel coordinat is x:460 y:261 So when i want to show color where mouse on over, it shows another color because of wrong coordinats. might i convert to coordinats? Bitmap bitmap = new Bitmap("C:\\TV2.bmp"); int width = bitmap.Width; int height = bitmap.Height; int i, j; for (i = 0; i< width; i++) { for (j=0; j -- modified at 6:03 Friday 5th May, 2006

          R 1 Reply Last reply
          0
          • G Greeky

            thank you I found this sample so GetPixel and SetPixel is ok for me. My new question is my picture box is set to Strech view. My image's width =768 , height=503 but on secreen, rightbottom corner pixel coordinat is x:460 y:261 So when i want to show color where mouse on over, it shows another color because of wrong coordinats. might i convert to coordinats? Bitmap bitmap = new Bitmap("C:\\TV2.bmp"); int width = bitmap.Width; int height = bitmap.Height; int i, j; for (i = 0; i< width; i++) { for (j=0; j -- modified at 6:03 Friday 5th May, 2006

            R Offline
            R Offline
            Robert Rohde
            wrote on last edited by
            #5

            Hi, might be difficult because the PictureBox won't reveal this. You could try to calculate it yourself (not tested):

            float sw = 1f * pictureBox.Width / bitmap.Width;
            float sh = 1f * pictureBox.Height / bitmap.Height;
            int xPic = xMouse * sw;
            int yPic = yMouse * sh;

            where x/yMouse are the mouse coordinates you are getting and x/yPic should be the coordinates within the picture. But I don't know if this is accurate enough (might be that you'll also have to consider the border of the PictureBox).

            1 Reply Last reply
            0
            • G Greeky

              For example,you have picture(is painted with solid colors not gradiant) at mspaint, I would like to change all X color to Y color. How could i achive that? Is there any method at Drawing class (i coulnd find any :'()

              I Offline
              I Offline
              Insincere Dave
              wrote on last edited by
              #6

              You can also replace colors using the ImageAttributes and ColorMap classes. Example replaces red->yellow, blue->magenta. Graphics g = Graphics.FromImage(im); ImageAttributes attr = new ImageAttributes(); ColorMap[] remap = new ColorMap[2]; remap[0] = new ColorMap(); remap[0].OldColor = Color.Red; remap[0].NewColor = Color.Yellow; remap[1] = new ColorMap(); remap[1].OldColor = Color.Blue; remap[1].NewColor = Color.Magenta; attr.SetRemapTable(remap); g.DrawImage(im, new Rectangle(0, 0, im.Width, im.Height), 0, 0, im.Width, im.Height, GraphicsUnit.Pixel, attr);

              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