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. Grey Scale Image error??

Grey Scale Image error??

Scheduled Pinned Locked Moved C#
helpgraphicsquestion
14 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.
  • L Luc Pattyn

    You have modified a bitmap in memory; how would that affect your display ? To get a visual change you must: - make sure the bitmap is shown somewhere in a Form or Control (e.g. it gets drawn in a Panel); - tell that Form/Control that it needs to redraw because its content has changed; you do this by calling Control.Invalidate() Now a 2*2 bitmap probably is hardly visible at all, so dont expect a huge change in your display when you grayscale it ! :)

    Luc Pattyn [My Articles] [Forum Guidelines]

    S Offline
    S Offline
    Software_Specialist
    wrote on last edited by
    #5

    Sorry but its not too clear to me.... How to show bitmap on form or control ??? How to tell the form that it needs to redraw...? And then how can i get a good change in display if 2*2 wont make much differnce..? Thanks

    L 1 Reply Last reply
    0
    • S Software_Specialist

      Sorry but its not too clear to me.... How to show bitmap on form or control ??? How to tell the form that it needs to redraw...? And then how can i get a good change in display if 2*2 wont make much differnce..? Thanks

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

      Software_Specialist wrote:

      How to show bitmap on form or control ???

      by drawing it in the form/control's paint handler, using Graphics.DrawImage

      Software_Specialist wrote:

      How to tell the form that it needs to redraw...?

      see previous message

      Software_Specialist wrote:

      And then how can i get a good change in display if 2*2 wont make much differnce..?

      try a larger bitmap !

      Luc Pattyn [My Articles] [Forum Guidelines]

      S 1 Reply Last reply
      0
      • S Software_Specialist

        oh yeh...now i initialized it as b = new Bitmap(2,2); exception is solved but after i press button for grey scale..Nothing is happening. Cursor is going to Invalidate. And no change in pic Thanks

        A Offline
        A Offline
        Amar Chaudhary
        wrote on last edited by
        #7

        Debug

        1 Reply Last reply
        0
        • L Luc Pattyn

          Software_Specialist wrote:

          How to show bitmap on form or control ???

          by drawing it in the form/control's paint handler, using Graphics.DrawImage

          Software_Specialist wrote:

          How to tell the form that it needs to redraw...?

          see previous message

          Software_Specialist wrote:

          And then how can i get a good change in display if 2*2 wont make much differnce..?

          try a larger bitmap !

          Luc Pattyn [My Articles] [Forum Guidelines]

          S Offline
          S Offline
          Software_Specialist
          wrote on last edited by
          #8

          ok now i know what you mean... you mean to write as shown below::: protected override void OnPaint (PaintEventArgs e) { Graphics g = e.Graphics; g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, (int)(m_Bitmap.Width*Zoom), (int)(m_Bitmap.Height * Zoom))); } And for this i have to remove the picture box from the form. But i am writing an application for image viewer. i.e. Slide show and for that i need few of the image processing stuff..So for that i guess i need to have picture box .. Moreover its not working out for me. I have just tried to load the picture with a following code private void File_Load(object sender, System.EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\" ; openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg"; openFileDialog.FilterIndex = 2 ; openFileDialog.RestoreDirectory = true ; if(DialogResult.OK == openFileDialog.ShowDialog()) { m_Bitmap = (Bitmap)Bitmap.FromFile(openFileDialog.FileName, false); this.AutoScroll = true; this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom)); this.Invalidate(); } } But it gives me a blinkin form..I mean photo is not stable. It comes and go off every msec... Well i am referring http://www.codeproject.com/cs/media/csharpgraphicfilters11.asp Any solution...??? Thanks

          L 1 Reply Last reply
          0
          • S Software_Specialist

            ok now i know what you mean... you mean to write as shown below::: protected override void OnPaint (PaintEventArgs e) { Graphics g = e.Graphics; g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, (int)(m_Bitmap.Width*Zoom), (int)(m_Bitmap.Height * Zoom))); } And for this i have to remove the picture box from the form. But i am writing an application for image viewer. i.e. Slide show and for that i need few of the image processing stuff..So for that i guess i need to have picture box .. Moreover its not working out for me. I have just tried to load the picture with a following code private void File_Load(object sender, System.EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\" ; openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg"; openFileDialog.FilterIndex = 2 ; openFileDialog.RestoreDirectory = true ; if(DialogResult.OK == openFileDialog.ShowDialog()) { m_Bitmap = (Bitmap)Bitmap.FromFile(openFileDialog.FileName, false); this.AutoScroll = true; this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom)); this.Invalidate(); } } But it gives me a blinkin form..I mean photo is not stable. It comes and go off every msec... Well i am referring http://www.codeproject.com/cs/media/csharpgraphicfilters11.asp Any solution...??? Thanks

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

            I never felt the need for a PictureBox, I prefer drawing on a Panel, so I know exactly what is being drawn, how it gets scaled, etc. I never used AutoScroll but I think your AutoScrollMinSize is wrong; I suggest you try it once without that line... :)

            Luc Pattyn [My Articles] [Forum Guidelines]

            S 1 Reply Last reply
            0
            • L Luc Pattyn

              I never felt the need for a PictureBox, I prefer drawing on a Panel, so I know exactly what is being drawn, how it gets scaled, etc. I never used AutoScroll but I think your AutoScrollMinSize is wrong; I suggest you try it once without that line... :)

              Luc Pattyn [My Articles] [Forum Guidelines]

              S Offline
              S Offline
              Software_Specialist
              wrote on last edited by
              #10

              well no its not working without that aswell... I am referring to CG article and in his demo its workin fine. And yeah i am not drawing it on panel...Its just a form and that override command. And what about slide show ? Would i be able to get that functionality if i draw on form without using picturbox.. ? Thanks

              L 1 Reply Last reply
              0
              • S Software_Specialist

                well no its not working without that aswell... I am referring to CG article and in his demo its workin fine. And yeah i am not drawing it on panel...Its just a form and that override command. And what about slide show ? Would i be able to get that functionality if i draw on form without using picturbox.. ? Thanks

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

                a picturebox is like a panel that knows how to load an image file, and how to draw an image; you already did both. To make a slide show you just need to load and display consecutive images, triggered by something (maybe a button click, maybe a timer tick). BTW: you must Dispose of your OpenFileDialog ! :)

                Luc Pattyn [My Articles] [Forum Guidelines]

                S 1 Reply Last reply
                0
                • L Luc Pattyn

                  a picturebox is like a panel that knows how to load an image file, and how to draw an image; you already did both. To make a slide show you just need to load and display consecutive images, triggered by something (maybe a button click, maybe a timer tick). BTW: you must Dispose of your OpenFileDialog ! :)

                  Luc Pattyn [My Articles] [Forum Guidelines]

                  S Offline
                  S Offline
                  Software_Specialist
                  wrote on last edited by
                  #12

                  yo removed OpenFileDialog and now using direct instance of it.. But no work as yet..Ok ill try to figure it out .... Actually i am new to IP. But thanks for pointing me out these basic things..and so to basically we dont need any panel or picturebox dropped over form..We can just draw it once...oks ill try to figure out the prob nw... cheers

                  L 1 Reply Last reply
                  0
                  • S Software_Specialist

                    yo removed OpenFileDialog and now using direct instance of it.. But no work as yet..Ok ill try to figure it out .... Actually i am new to IP. But thanks for pointing me out these basic things..and so to basically we dont need any panel or picturebox dropped over form..We can just draw it once...oks ill try to figure out the prob nw... cheers

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

                    What I meant is you must call openFileDialog.Dispose() when you no longer need that instance of OpenFileDialog, otherwise you may get a memory leak. :)

                    Luc Pattyn [My Articles] [Forum Guidelines]

                    S 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      What I meant is you must call openFileDialog.Dispose() when you no longer need that instance of OpenFileDialog, otherwise you may get a memory leak. :)

                      Luc Pattyn [My Articles] [Forum Guidelines]

                      S Offline
                      S Offline
                      Software_Specialist
                      wrote on last edited by
                      #14

                      yeh got the solution to it...well doublebuffer property was set to false... So i setted it to true and is working now... :) ta

                      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