473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Q: BitBlt destination is always "blank" (VC++, .NET)

Hi Folks,

My setup: Visual Studio Express 2008, VC++, .NET, 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:
Expand|Select|Wrap|Line Numbers
  1. MainMenuForm_Shown(...)
  2. {
  3. Graphics ^formGraphics = this->CreateGraphics();
  4. Bitmap ^bitmap = gcnew Bitmap(this->Width, this->Height, formGraphics);
  5. Graphics ^bitmapGraphics = Graphics::FromImage(bitmap);
  6. IntPtr formDC = formGraphics->GetHdc();
  7. IntPtr bitmapDC = bitmapGraphics->GetHdc();
  8.  
  9. BitBlt(bitmapDC, 0, 0, this->Width, this->Height, formDC, 0, 0, 0xCC0020);
  10.  
  11. formGraphics->ReleaseHdc(formDC);
  12. bitmapGraphics->ReleaseHdc(bitmapDC);
  13.  
  14. bitmap->Save(CCarthageDefs::DIR_IMAGES + "test.jpg");
  15. }
  16.  
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:
Expand|Select|Wrap|Line Numbers
  1. Bitmap ^srcImage = gcnew Bitmap("input.jpg");
  2. Graphics ^srcG = Graphics::FromImage(srcImage);
  3. Bitmap ^toImage = gcnew Bitmap(srcImage->Width, srcImage->Height,
  4. srcG);
  5. Graphics ^toG = Graphics::FromImage(toImage);
  6.  
  7. IntPtr srcDc = srcG->GetHdc();
  8. IntPtr toDc = toG->GetHdc();
  9.  
  10. BitBlt(toDc, 0, 0, srcImage->Width, srcImage->Height, srcDc, 0, 0,
  11. 0xCC0020);
  12.  
  13. srcG->ReleaseHdc(srcDc);
  14. toG->ReleaseHdc(toDc);
  15.  
  16. srcImage->Save("test1.jpg");
  17. toImage->Save("test2.jpg");
  18.  
---
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 27 '08 #1
0 1782

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: JohnS | last post by:
Hi, When I initially start my browser (any of 'm) and point it to my PHP script the $PHPSESSID is always blank. On all subsequent hits or after a refresh the value for $PHPSESSID is fine... why...
4
by: John Baker | last post by:
Hi: I have a query which supports a form. Te form is used to edit, update and change records in the table the query is based on. It all works fine EXCEPT that the "New" record (blank updatable...
1
by: John | last post by:
Hi I need to print "blank" invoices with invoice numbers only at the top. I have a table full of invoice numbers which I am using as the record source for the invoice report. I have placed the...
1
by: James Pang | last post by:
myProcess.StartInfo.FileName==@"C:\WINDOWS\system32\ping.exe 10.0.0.1"; //this will not work cant find file name... myProcess.StartInfo.FileName==@"C:\WINDOWS\system32\ping.exe"; //this works...
4
by: sid | last post by:
"about:blank" oepns new browser window I am writing a webpage that will run on other machines that I may or may not know about. My page is framed where frame1 controls the content of frame2. ...
1
by: sid | last post by:
I am writing a webpage that will run on other machines that I may or may not know about. My page is framed where frame1 controls the content of frame2. What I have found is that if the page in...
1
by: =?Utf-8?B?Y3JhbmtlX2JveQ==?= | last post by:
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...
5
by: dougmeece | last post by:
I have two forms with one calling the other to perform searches. When I run the search form the 2nd form a blank record is added to my table. The table is appended or updated from entries on the...
0
by: =?Utf-8?B?SlA=?= | last post by:
I have an application that uses Forms Authentication in connection with Active Directory for granting access to an application. When a user logs on with AD, it populates the AUTH_USER...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.