Solved

BitBlt of picturebox

Posted on 2011-03-14
5
960 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 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