|
*grin* yeah, I think that's what he needs to use.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Mark Salsbery wrote: ...and the Silverlight forum too!
Had to give him the hint, didn't you?
2 75 22 6
|
|
|
|
|
O M G
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a winform which has a UserControl in it that I use for drawing. The only drawing it does is creating rectangles made by user using mouse. Now, I need to add two comboboxes next to each rectangle. I created a UserControl which has two comboboxes in it. When a rectangle is done I create a new UserControl and it to the page, placing next to the new rectangle. Now this works fine but after a few rectangles (and combobox UserControls) the cpu usage goes off the charts while drawing new rectangle. While idle there's no cpu usage but drawing becomes impossible. With UserControl without comboboxes or without any UserControls (only drawed rectangles) this problem doesn't happen. Also I only have one Graphics, I use the only one comes with PaintEventArgs.
The UserControl I use for drawing is very similar to DrawTools here[^].
Any idea about what's the problem is or other ways to add comboboxes next to the rectangles? I'd appreciate any help..
|
|
|
|
|
I'm not sure how your invalidating your form but if your invalidating the entire area everytime the dynamic rectangle is resized then you will see a performance hit. If your not familiar with Clipping an invalidation area, I suggest you do a google search on "Invalidation+Clipping".
Cheers,
Richard
If you could rent a programmer a hour and a half for a dollar and a half, how much would he charge for 10 hours?
|
|
|
|
|
programmingAddict wrote: I'm not sure how your invalidating your form but if your invalidating the entire area everytime the dynamic rectangle is resized then you will see a performance hit.
The UserControl displays an image as background. I use Refresh() at:
1. When new image is assigned
2. New rectangle is added
3. Rectangle is resized
Also on OnPaint() event I use graphics.DrawImage for the image and graphics.DrawRectangle for all the rectangles. Combobox UserControls are added with this.Controls.Add() and I don't do anything specific to draw them.
The form and UserControl size doesn't change at all.
I set double buffering true on drawing UserControl and on combobox UserControl.
Anything I overdone/done bad?
modified on Saturday, May 3, 2008 12:44 PM
|
|
|
|
|
Hi,
I tend to never use Refresh(), I call Invalidate() instead.
Refresh is Invalidate+ImmediateRepaint which typically is more than what is really
necessary, so I suggest you try with Invalidate().
If that results in some parts not being updated, then your architecture is wrong;
Refresh() should be used only when it is essential to have something redrawn right away
say for better esthetics, not to get it right.
|
|
|
|
|
How do I write my own Autobalance code, like Acdsee and Photoshop have? I can't find it anywhere. It is not equalize cause the result doesnt look like anything as good as in the forementioned apps.
I believe I need the Histogram for this purpose, but where do I go from here?
Thanks
|
|
|
|
|
Hi Guys,
I am really stuck here, unable to find any solution on the net, and hence would like to ask all you experts out there...if you could please please help me...
I am using the GDI+ Graphics Class in VS2005 (.NET FW 2.5), to write text in a form of mine.
The form however, has multiple (multi-colored) pictures and background images. Thats why I chose Graphics.DrawString to write over these images.
Now, I want that once a text has been displayed, on another button click, this text should be erased, and instead a new one should be displayed.
The problem right now is, when i write the new text, C# writes it over the old one..and well u can imagine how it looks like then... unreadably gibberish! And thats coz i cant figure out how to erase the old text, i believe.
Any ideas people??
-Thanks a million!!
|
|
|
|
|
Don't draw on your image, draw on the screen in your paint event.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi all,
Can i know how to force to refresh the graphic?
Any tips are welcome.
Note: I am using override OnPaint and render() method to display the graphic.
regards
cocoonwls
|
|
|
|
|
A bit of background information would be usefull (even needed). Which technologies are you using ? A wild guess because I recognize OnPaint is that you are using the MFC's in C++ (but as I'm not familiar with other technologies, it can be completely wrong).
If that's the case, calling Invalidate will force a redraw of your window.
|
|
|
|
|
Hi Cedric,
Thanks for reply, I am using buffer graphic (GDI technologies in c#)to draw into off screen. then use Render() method to display on screen.Note that, these drawing method is develop in my Custom User Control. here are some samples code :
FrmMain : TimewayChartControl
private void DrawChart()<br />
{<br />
TimewayChartControl.CreatBufferGraphics(); <-----create buffergraphic<br />
TimewayChartControl.RenderLinePath(); <-----draw line<br />
}
Custom Control:
BufferedGraphicsContext CurrentContext = BufferedGraphicsManager.Current;<br />
BufferedGraphics bg;
public void CreatBufferGraphics()<br />
{<br />
bg = CurrentContext.Allocate(this.CreateGraphics(), this.ClientRectangle);<br />
bg.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;<br />
bg.Graphics.Clear(this.BackColor);<br />
}
private void DrawLinePath(Graphics g)<br />
{<br />
g.DrawPath(LinePathPen, gpLine);<br />
}
protected override void OnPaint(PaintEventArgs pe)<br />
{<br />
bg.Render(pe.Graphics);<br />
}
Everytime when after i draw the first graphic, the second graphic which i draw will not render unless some frame or other form move over the painting area, then only the second graphic will appear and erase the first graphic.... I am not sure what was happen
|
|
|
|
|
Hi Cedric,
i have try to use invalidate in my application, but seem it dosen't work for me
I try to add Invalidate after calling TimewayChartControl.RenderLinePath(); , it dosen't work (please point it out if i was wrong,thanks).
|
|
|
|
|
I don't know C# but what you have to do (it's still windows so it's the same for C++ and C#) is that you need to put all the rendering stuff in the OnPaint method and nowhere else. Thus if you want to draw a line, you need to store the information somewhere and draw the line in the OnPaint handler.
|
|
|
|
|
Read this over at MSDN:
Update[^]
Invoking Invalidate on a control client area or a window, for that matter, merely queues the message so that at the next system WM_PAINT message for that control, it is repainted as you specify. It doesn't force an immediate repaint. Calling Update causes the system to send the control a WM_PAINT message which repaints any invalidated regions, or does nothing if there are no invalidated regions. Windows considers painting an expensive operation, and so only does this when necessary.
Typically, you call Invalidate and then Update.
modified on Sunday, May 4, 2008 5:47 PM
|
|
|
|
|
hI Baltoro,
Thanks, it work for me when i calling update. 
|
|
|
|
|
This is probably a simple problem as the most I've ever done with GDI was a simple ray tracer that drew a circle on a flat plain using drawline ALOT. Needless to say... I'm a GDI nub.
So anyway, I tried to use Bitmap.Save to take a screenshot of each of the windows on a WinForm application. This works great on the first run, but if I run the function a second time an exception is thrown where I called the save.
I decided to use a filestream so I'd have control over the stream instead of passing a pathname. Even though I close the stream when I'm done with it, it throws a file in use exception when I try to create the stream on the second go around.
Here's my current code:
<br />
Bitmap mybmp = new Bitmap(formwidth, formheight,PixelFormat.Format32bppArgb)<br />
<br />
System.IO.FileStream fs = System.IO.File.Open(imagePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);<br />
<br />
mybmp.Save(fs, ImageFormat.Jpeg);<br />
fs.Close();<br />
Am I missing something here?
|
|
|
|
|
This doesn't help much, but your code works fine for me - calling it multiple times.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If you were to open the same file using Bitmap bm = new Bitmap(imagePath) somewhere, THEN it would be locked as long as that bitmap was open. Using a filestream to open a bitmap and closing the stream, solves the problem.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Take a GIF.
My GIF for example:
http://reelix.googlepages.com/ReeFlame.gif[^]
Look at in in the browser... Looks good, hey? (Well, my opinion anyways)
Save it to Windows (I can only test with XP - Not sure if it does it in Vista)
Open it in Windows Default Image Viewer.
Laaaaaaggg....
Any reason for this?
Was looking into C# GDI+ GIF Animation, and this... Issue arose...
Any ideas, anyone?
- Reelix
|
|
|
|
|
Looks the same to me either way. Also animating at the same speed.
Best Wishes,
-David Delaune
|
|
|
|
|
Found it does the same in IE (Seems to be the same Bug) - Sure you're not an IE Fan? :p
Try the same GIF in FireFox.
Havn't tried Opera Yet...
- Reelix
P.S: If anyone is interested... I suceeded with my C# GDI+ GIF Animation:
http://reelix.googlepages.com/gifAnimation.txt[^]
|
|
|
|
|
Reelix wrote: Sure you're not an IE Fan?
Like many people these days I use multiple browsers. I have checked the GIF file in IE Opera and Safari and there is no lag I can detect visually.
Reelix wrote: Try the same GIF in FireFox.
I'll take your word for it instead. I am not a big fan of past releases of Firefox. I will take a look at the next generation of Firefox when it is released. I have read an article about how they optimized image cache and greatly improved memory management. But for now I am happy with IE and Opera.
Best Wishes.
-David Delaune
|
|
|
|
|
Hi all,
I have created a double buffering drawing method,the code as below:
BufferedGraphicsContext CurrentContext = BufferedGraphicsManager.Current;
BufferedGraphics bg = CurrentContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
bg.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
bg.Graphics.Clear(this.BackColor);
this.draw(bg.Graphics)
bg.Render();
bg.Dispose();
My question is how can i draw the graphic to bitmat or any type of picture?
Note: This drawing method is build in custom user control
thanks in advance
cocoon
|
|
|
|