tags:

views:

95

answers:

2

Hi Im doing this paint application its kind simple it consist of a panel where i will draw on and then finally I will save as jpg or bmp or png file.

My aplication work perfectly but the problem Im facing is that when Im saving the output is not what drawn on the panel its black Image nothing just black.

all my work is been saved as

Thepic = new Bitmap(panel1.ClientRectangle.Width, this.ClientRectangle.Height);

and on the mouse (down,up thing) I have

snapshot = (Bitmap)tempDraw.Clone();

and it saved the work normally but again the rsult is black Image not what the panel contain

I hope I Explaind well ....

Thanx in advance

+2  A: 

I think the problem may be that you're using the "Clone" method.

Try "DrawToBitmap" - that's worked for me in the past.

Here's a sample that saves a bitmap from a control called "plotPrinter":

        int width = plotPrinter.Size.Width;
        int height = plotPrinter.Size.Height;

        Bitmap bm = new Bitmap(width, height);
        plotPrinter.DrawToBitmap(bm, new Rectangle(0, 0, width, height));

        bm.Save(@"C:\TestDrawToBitmap.bmp", ImageFormat.Bmp);
Tom Bushell
This works great for controls with no child controls, but when the control has child controls, `DrawToBitmap` draws the children in reverse the 'z' order (meaning behind controls are drawn in front of the real front controls).
Zach Johnson
Thanx a lot your solution work ....
Tony
A: 

Hi ,

I am in the situation and i do want to to save the drawing (contents) on a panel as an image using C# and asp.net.But when i give the below code,its telling

 int width =Convert.ToInt32(Panel1.Width);
    int height = Convert.ToInt32(Panel1.Height);
    Bitmap bmp = new Bitmap(width,height);       
    Panel1.DrawToBitmap//no definition or missing assembly

could you please help by posting ur code Thanks,

Vani