473,785 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Q: (.NET/GDI/BitBlt) Problem copying form to bitmap

Hi Folks,

I'm not sure where this post belongs since I'm using managed vc.net, but the
issue is around GDI BitBlt.

Here is a summary of the problem:
- I am trying to copy a bitmap of my main form into a picture box.
- To do this, I bitblt using the device contexts of the form and a bitmap
object.
- After blitting, the bitmap image is always blank. I don't understand what
I'm doing wrong here.

Here is my relevant code:

MainMenuForm_Sh own(...)
{
Graphics ^formGraphics = this->CreateGraphics ();
Bitmap ^bitmap = gcnew Bitmap(this->Width, this->Height, formGraphics);
Graphics ^bitmapGraphics = Graphics::FromI mage(bitmap);
IntPtr formDC = formGraphics->GetHdc();
IntPtr bitmapDC = bitmapGraphics->GetHdc();

BitBlt(bitmapDC , 0, 0, this->Width, this->Height, formDC, 0, 0, 0xCC0020);

formGraphics->ReleaseHdc(for mDC);
bitmapGraphics->ReleaseHdc(bit mapDC);

bitmap->Save(CCarthage Defs::DIR_IMAGE S + "test.jpg") ;
}

After running the above code, the file test.jpg is tiny and basically blank
(maybe all solid grayish white). I expected it to be a copy of the form.
Any comments on why this is happening would be most appreciated.

I thought maybe the problem was with the form, so I tried an even simpler
test: copying one image to another. Here is the code:
Bitmap ^srcImage = gcnew Bitmap("input.j pg");
Graphics ^srcG = Graphics::FromI mage(srcImage);
Bitmap ^toImage = gcnew Bitmap(srcImage->Width, srcImage->Height,
srcG);
Graphics ^toG = Graphics::FromI mage(toImage);

IntPtr srcDc = srcG->GetHdc();
IntPtr toDc = toG->GetHdc();

BitBlt(toDc, 0, 0, srcImage->Width, srcImage->Height, srcDc, 0, 0,
0xCC0020);

srcG->ReleaseHdc(src Dc);
toG->ReleaseHdc(toD c);

srcImage->Save(CCarthage Defs::DIR_IMAGE S + "test1.jpg" );
toImage->Save(CCarthage Defs::DIR_IMAGE S + "test2.jpg" );
---
After running the above code, test1.jpg (an output of the source image) is a
correct copy of the source image. test2.jpg is *blank*?? Again, something
with the BitBlt seems to have failed ...

Also, to make sure I was actually hitting the genuine BitBlt code, I tried
using the options BLACKNESS and WHITENESS. Both worked ... the destination
turned the appropriate color.

Finally, in case anyone is interested in why I'm doing this ... I am having
some ugly flicker at the load-up of my form. I'm trying to take a copy of
the form's look, put it in a screen-sized picture box, and display that to
the user before they see the real form.

Thanks

Mar 26 '08 #1
1 3162
I thought the following might also be helpful:
- I tried to use control->DrawToBitmap() . but it doesn't draw all the
sub-controls that I need it to.
- I am using VC++ under Visual Studio Express 2008.
- Here is my prototype for BitBlt:
[System::Runtime ::InteropServic es::DllImportAt tribute("gdi32. dll")]
extern bool BitBlt(IntPtr hDestDC,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hSrcDC,
int xSrc,
int ySrc,
int dwRop);

Mar 26 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1324
by: Pavan Arise | last post by:
Hi all.. I have this particular problem. I have a form with some plotting done on that. Now, I was wondering if I could copy the whole drawing/plotting of that form onto a different form & then do some other plotting on the first form afresh. Is there any way to do this? I would be thankful for any ideas or suggestions. Thanks in advance. Regards, Pavan.
1
1236
by: Steve Darby | last post by:
Hi there, How can I copy content from one form field into another at the click of a button?
3
13912
by: Jerry Q | last post by:
Hello, Where could aI find a sample code which would show how to use Marshal.Copy to copy a "graphics image" to pixel based image? There is a MS (really) quick supportpage for that http://support.microsoft.com/kb/814675/en-us but it is too approximate for anything. Cheers!
15
7197
by: dgk | last post by:
I'm trying to save the image of a webbrowser control. Not a particular image being shown on the page, but rather the visible display of the webbrowser. Using VS2005 I figured that maybe DrawToBitmap would work, but it appears that the webbrowser doesn't implement it. So I looked around and found that this code: Dim g As Graphics g.CopyFromScreen(Me.wb1.PointToScreen(New Point(0, 0)), New Point(0, 0), wb1.Size)
3
1768
by: Dave | last post by:
Hey all, I have a problem and I can't find anything on the net to really address it. We have a program at work that has lots of numbers on the front of the form because it is a control program for a hydro plant. My boss would like me to create a web page so our control center can see all of the numbers but not have access to the actual form. Some of these numbers are gathered every second, others every five seconds and still others...
1
6295
by: MLM450 | last post by:
I am creating a bitmap using a memory stream. Is there any way to load the bitmap data so the memory stream can be disposed? Perhaps copying the bitmap in some simple, quick way? Thanks
15
1853
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
2
2818
by: raylopez99 | last post by:
Beware newbies: I spent a day before I figured this out: copying a bitmap (image) file to file is not quite like copying a text file--you have to do some tricks (see below), like using a "Graphics" object to wrap around the image (!). It's not so simple as shown in most examples (where they have a simple image file and hard copy it into a harddrive along the lines of : image.Save(@"C:\\temp\\myimage.pgn"); That will work, but it's a...
1
2357
by: tbaxter | last post by:
Hello all, I'm seeing something very odd when I create a System.Drawing.Bitmap from an existing Bitmap. If the original Bitmap has a resolution of 72x72, the new resulting Bitmap has a resolution of 96x96. I was wondering if anyone knows why this is happening. The fact that the resolution is changing on me is causing me grief (yes, I know I can call "SetResolution()"). Below is some sample code with comments indicating the output. I have...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.