Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1026
  • Last Modified:

BitBlt of picturebox

I have 2 pictures box.  One already got a bitmap loaded, and i would like to try to do a copy with BitBlt.  I know that there's probably already a function to do that, but i'm trying to test the performance of a bitblt in c# thru pinvoke vs c++.

How do i get the HDC of the picture boxes?

thanks
0
Christian de Bellefeuille
Asked:
Christian de Bellefeuille
3 Solutions
 
Luis PérezSoftware Architect in .NetCommented:
Check this, I think this is what you're looking for.

http://www.eggheadcafe.com/software/aspnet/30688052/the-mighty-bitblt.aspx

Hope that helps.
0
 
Mohamed AbowardaSoftware EngineerCommented:
You need to use GetDC API to get the picturebox hDC:
http://msdn.microsoft.com/en-us/library/dd144871(v=vs.85).aspx

1. Add the line "using System.Runtime.InteropServices;" above the namespace
2. Add the following line to your form class:
    [DllImport("user32.dll")]
    public static extern IntPtr GetDC(IntPtr hWnd);

3. Use the following code to get the picturebox hDC
IntPtr hDC = GetDC(pictureBox1.Handle);

Open in new window

0
 
Christian de BellefeuilleProgrammerAuthor Commented:
Thanks a lot Medo, it work just fine!
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
...be sure to use ReleaseDC() to prevent GDI leaks.
0
 
Mohamed AbowardaSoftware EngineerCommented:
You are very welcome :)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now