Link to home
Start Free TrialLog in
Avatar of dannyhop
dannyhop

asked on

Rendering a background image in C# using Win32 API - BitBlt

Hi All,
I am trying to render an API image to a background (image) memory location then use that image as a source for a BitBlt API call.
In my former life as a VB6 programmer I could simply render the image to a PictureBox (located off screen) with AutoRedraw = True.
I realize that this wasn't 'technically' rendering to memory but it served the purpose of giving me an 'off screen' intermediate memory location that had a HDC handle so I could use the hidden image as a source for BitBit.

I now find myself in the .NET - C# (C sharp) world trying to accomplish this same feat.
I can render from the EM_Message to an intermediate picture box but if it is not located in a visable area of the screen, it will not render.  This method acts like the old VB6 PictureBox with AutoRedrw = False.

I made a stab it it below....

1st I create a memory bitmap called intImage...
            Bitmap intImage = new Bitmap(533, 165);
then get a handle to it...
            IntPtr memHDC = intImage.GetHbitmap();

I have a feeling that maybe I am not creating a 'Graphic' but I am unsure how to do that?

Or maybe I just missing something simple that would allow me to render an API painted image in the background.

FYI - Note: I am using EM_FORMATRANGE (below) to render the initial image and it works fine when rendered to a PictureBox.
    //Render the selected RTF text into the tempPicBox hdc (from FORMATRANGE structure)
            res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);

Thank You in advance for your time and kind assistance.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also be aware that the exposed graphics object will let you accomplish what BitBlt used to be used for. In fact, most GDI functions are much easier to work with from managed .NET objects.
Yeah...see his last PAQ:
https://www.experts-exchange.com/questions/24648194/I-need-to-create-a-bitmap-image-of-each-screen-or-line-in-a-scrolled-richTextBox-file-using-C.html

He's trying to draw a RichTextBox to a Bitmap and it wasn't playing nicely as it's an exception to the rule.  =\
Avatar of dannyhop
dannyhop

ASKER

One line makes all the difference...
This .NET world is different but, for the most part... Way better....
Just needed to convert a few of these old API things.
Needed to use old API BitBlt as .NET graphics does not have quite fast enough refresh rate.
Thanks...  Works great!
I see, already been down that road have we? : -)