Solved

BitBlt of picturebox

Posted on 2011-03-14
5
939 Views
Last Modified: 2013-12-17
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
Comment
Question by:cdebel
5 Comments
 
LVL 25

Assisted Solution

by:Luis Pérez
Luis Pérez earned 100 total points
ID: 35129235
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
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 350 total points
ID: 35129954
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
 
LVL 10

Author Comment

by:cdebel
ID: 35130582
Thanks a lot Medo, it work just fine!
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 50 total points
ID: 35130608
...be sure to use ReleaseDC() to prevent GDI leaks.
0
 
LVL 12

Expert Comment

by:Mohamed Abowarda
ID: 35130659
You are very welcome :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now