Jump to content
Xtreme .Net Talk

qmp

Members
  • Posts

    14
  • Joined

  • Last visited

Everything posted by qmp

  1. I have a picturebox with an image property set to a standard jpg file and the properties set to stretch the image to fit the picturebox size.. Now, what I want to do is copy a section from that picture box (with the new stretched image) to a seperate picture box. So the second picturebox would have a copy of the stretched image, not the original image.. How do I copy, say a 100x100 chunk of the stretched picturebox image to another picturebox? I am so far only able to copy the image in its unstretched form.
  2. With help from this forum I was able to figure out the double buffer solution using gdi32's BitBlt in C#.net. GDI+ is well known for its lack of speed in the performance arena. To solve the "flicker" solution, and add a fast back buffer to my application, i dipped back into gdi32. What you'll want to do is this.. On your form, create a picturebox that will show your live drawing. Lets call it picChart. Now, what we need to do is create a back buffer for our picChart. private Bitmap memBmp; // Backbuffers bitmap private IntPtr hMemBmp; // Handle to our memBmp private Graphics memDC; // We draw on this private IntPtr hMemdc; // Handle to our memDC private void picChart_Resize(object sender, EventArgs e) { // If we have already created a dc for mem, lets free it up first if (hMemdc.ToInt32() != 0) { // Clean up DeleteObject(hMemBmp); DeleteDC(hMemdc); memBmp.Dispose(); } // Resize our backbuffer memBmp = new Bitmap(picChart.Width, picChart.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555 ); Graphics clientDC = picChart.CreateGraphics(); IntPtr hdc = clientDC.GetHdc(); hMemdc = CreateCompatibleDC(hdc); // hMemdc is the handle to our memDC hMemBmp = memBmp.GetHbitmap(); SelectObject(hMemdc, hMemBmp); memDC = Graphics.FromHdc(hMemdc); // We draw on memDC // Clean up clientDC.ReleaseHdc(hdc); clientDC.Dispose(); } private void picChart_Paint(object sender, PaintEventArgs e) { // Copy Region from memDC IntPtr hdc = e.Graphics.GetHdc(); BitBlt(hdc, e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height, hMemdc, e.ClipRectangle.X, e.ClipRectangle.Y, 0x00CC0020); e.Graphics.ReleaseHdc(hdc); } What the above code does is create a backbuffer the same size of our picChart every time the picChart is resized. If we have already created a backbuffer from a previous resize event, we delete the previous backbuffer from memory. Then in the picChart paint event, we will bitblt the exact region that was invalidated to our main picChart paint area. Also, in your form/controls dispose() method you will need to add: // If we have already created a dc for mem, lets free it up first if (hMemdc.ToInt32() != 0) { // Clean up DeleteObject(hMemBmp); DeleteDC(hMemdc); memBmp.Dispose(); } That will free up your backbuffer if it was created before the form/control disposes. To draw on your backbuffer, all you have to use is memDC.Drawxxx to draw whatever you like. It still uses GDI+ drawing techniques but will use the faster gdi32 bitblt to doublebuffer and repaint your form. Hope this helps.
      • 1
      • Like
  3. Ok.. I have a picChart picturebox on my form that resizes with the form. It is double buffered by me so when the picChart chagnes size, I must resize my backbuffer... I can do any of my drawing at any time using GDI+ and memDC. It works very well and my picChart is redrawn any time the user drags stuff over it. bitblt seems very fast as well although memDC.DrawLine does not seem as fast as GDI MoveToEx and LineTo.. but its very easy to implement. When the user resizes the form, i get SEVERE memory leaks.. I am completely lost now. I can't figure out the solution. I have tried using a static backbuffer size and instantiate it outside of the resize form but that still does not work. I'm at a loss now. private Graphics memDC; IntPtr memdc; private void picChart_Resize(object sender, EventArgs e) { // If we have already created a dc for mem, lets free it up first if (memdc.ToInt32() != 0) DeleteDC(memdc); // Resize our backbuffer Bitmap memBmp = new Bitmap(picChart.Width, picChart.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555 ); Graphics clientDC = picChart.CreateGraphics(); IntPtr hdc = clientDC.GetHdc(); memdc = CreateCompatibleDC(hdc); SelectObject(memdc, memBmp.GetHbitmap()); memDC = Graphics.FromHdc(memdc); // Clean up DeleteObject(memBmp.GetHbitmap()); clientDC.ReleaseHdc(hdc); clientDC.Dispose(); memBmp.Dispose(); // Clear out our back buffer memDC.FillRectangle(new SolidBrush(Color.Black), 0, 0, picChart.Width, picChart.Height); } private void picChart_Paint(object sender, PaintEventArgs e) { // Copy Region from memDC IntPtr hdc = e.Graphics.GetHdc(); IntPtr hMemdc = memDC.GetHdc(); BitBlt(hdc, e.ClipRectangle.X, e.ClipRectangle.Top, e.ClipRectangle.Width, e.ClipRectangle.Height, hMemdc, e.ClipRectangle.X, e.ClipRectangle.Y, 0x00CC0020); e.Graphics.ReleaseHdc(hdc); memDC.ReleaseHdc(hMemdc); }
  4. Ok.. so far so good.. In the OnPaint event for your picturebox it will have a e.Region or a rectangle or something (I forget the exact param)... but it will tell you the region that is being invalidated and then with that, you can bitblt that section onto your main image...
  5. I thank you all for your replies.. DirectX is out of the question. I do not doubt that it is more than adequate and is a great graphical method to use.. The reason I want to use GDI is because: GDI is proven to be faster than GDI+ I am very fluent in GDI and have working solutions built using GDI. The application is very similar to a sizemomitor (the earthquake meter).. with just a few more lines. Very similar to a lie detector test as well. In full screen mode, on slow machines, I do not think GDI+ will be up to the task. Plus.. like all of us, I'm on a time crunch. I have found solutions to create a hdc to draw on but have not found any that repaint the area when the area goes off screen/on screen. Per some of your advice, here is what I am thinking my approach is going to be. I will have to create a backbuffer to draw on.. and bitblt it to my main buffer which is viewable.. Then, if it goes off screen and on screen, i capture the onpaint event and re-bitblt that area from my backbuffer. I hope that will do it. PS. I'd like to add as well that I am very fluent in OpenGL and prefer OpenGL over DirectX.. ;)
  6. I am indeed using .net and am aware of the invalidate overloads. The charting size is dynamic, as big as the user wants.. so It could be full screen.. I'm still unclear as to the approach I must take. I wish there were some samples. I can't believe all charting in .net is done through GDI+ when performance critical apps could have problems. There must be some samples somewhere. I find it hard to believe I'm the first one doing this.
  7. I have the GDI solution done perfectly in VB6. It's gone through so many revisions and my current revision is very streamlined.. This is used for real time charting.. so speed is very important to me.. I will try to implement the back buffer solution.. The problem I see with that is every time I draw to the buffer I must invalidate the control which would redraw the entire control.. and that is very innefecient.. I want a way to be able to only have the certain area redrawn . hmmm.. still confused.
  8. Help.ShowHelp is exactly what I ended up going with... And for forms that you want to stick a simple help button on, where a user clicks it and it opens up the help you can do a sendkeys command with the F1 key as a parameter and it will invoke the help provider if you have one defined.
  9. I have much experience with GDI and VB6.. I have read about the slow performance of GDI+ and do not even want to attempt that. I want to implement GDI in .net.. I have a lot of source regarding the creation of a dhc and such but I am still kind of confused.. So, I want to start with the basics.. I'd like to create a picturebox?? .. or at least some sort of region... and for starters, lets just paint it all black .. Lets say I paint it by pressing a button on the form.. button executes the rect() fn to paint the square black.. Now, when I move the form off screen and back on, that paint is now gone? What is the solution for that? How do I implement that? Any examples you can lead me to? I assume once I have this basic buffering step taking care of, the drawing/updating task of completing this project will be fairly simple. Basically, I want to draw a meter... part of it is a filled rectangle, and then the other part is a numeric printout.. That stuff should be easy.. But making it stay visible when the user moves the form out of view and back on is confusing me. Thanks.
  10. Hmmm.. I'm ok for using either one as long as they will deploy the .net framework automatically. I'm currently using the MS plugin for the .net framework deployment. It's very clunkly. Lot's of clicking.
  11. I found the fix to be to erase the .projdata file in /obj/release after my compile script.
  12. Basically, I have a hardware inf/dll that I need to install with my installation software (.net), how do I go about doing this?
  13. After I use the command line builder devenv /rebuild release "myproj\myproj.csproj" or even devenv /rebuild release "myproj\myproj.prj" Next time I open up that project in dev studio none of my forms work. They only open up in code editor, not form designer.. How do I fix this?
  14. Instead of having the user have to hit F1, what if I want them to hit a button and open invoke the help provider... I'm not talking about just executing the chm process to open up a seperate chm process, I want to invoke it on the help providers process so if a user hits F1 on a different form, the same chm window is used. How do I go about doing this?
×
×
  • Create New...