Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats wrong here?

Status
Not open for further replies.

tomcoombs

Programmer
Aug 14, 2003
65
GB
Why is the image always black? Its not if a print it to the screen...

string strButton = "defaultt";

///new offscreen draw
Graphics offScreenDC;
Bitmap offScreenBmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
offScreenDC = Graphics.FromImage(offScreenBmp);
///new offscreen draw

///draw off screen stuff
offScreenDC.SmoothingMode = SmoothingMode.AntiAlias; //Make curves render better
Rectangle rect = new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
Brush brsh = new SolidBrush(Color.Gray);
offScreenDC.FillRectangle(brsh, rect);

Rectangle rect2 = new Rectangle(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
Pen pn = new Pen( Color.Black );
offScreenDC .DrawRectangle(pn, rect);
Font fnt = new Font("Verdana", 16);

offScreenDC.DrawString(strButton, fnt, new SolidBrush(Color.Black), 0,2);
///draw off screen stuff


Graphics clientDC = this.CreateGraphics();
clientDC.DrawImage(offScreenBmp, 0, 0);

Graphics g1 = offScreenDC;

Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"c:\Captured.bmp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");

Tom
 
try filling the offscreendc with white or something!
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top