Grey Scale Image error??
-
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]
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
-
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
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]
-
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
Debug
-
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]
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 codeprivate 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 -
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 codeprivate 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...??? ThanksI 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]
-
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]
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
-
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
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]
-
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]
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
-
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
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]
-
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]
yeh got the solution to it...well doublebuffer property was set to false... So i setted it to true and is working now... :) ta