Click here to Skip to main content
14,733,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI GUYS.
wrote this code to save a form as a bmp file:
if anybody know how can i save a form like a jpeg file say it to me.

save as a bmp:
private void button1_Click(object sender, EventArgs e)
        {

            this.FormBorderStyle = FormBorderStyle.None;
            this.BackColor = Color.White;
            
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.DefaultExt = "*.bmp";
            saveFileDialog.Filter = "bmp Files|*.bmp";
            saveFileDialog.FileName = FormMain.NamProzhe + ".bmp";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                SaveAsBitmap(this, saveFileDialog.FileName);
            }

            this.Close();
            
        }


save as bitmap :
public void SaveAsBitmap(Control control, string fileName)
        {
            //getthe instance of the graphics from the control
            Graphics g = control.CreateGraphics();

            //new bitmap object to save the image
            Bitmap bmp = new Bitmap(control.Width, control.Height);

            //Drawing control to the bitmap
            control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));

            bmp.Save(fileName);
            bmp.Dispose();
        }
Posted
Updated 5-Dec-12 0:31am
v2

private void button1_Click(object sender, EventArgs e)
        {

            this.FormBorderStyle = FormBorderStyle.None;
            this.BackColor = Color.White;

            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.DefaultExt = "*.jpeg";
            saveFileDialog.Filter = "jpeg Files|*.jpeg";
            saveFileDialog.FileName = FormMain.NamProzhe + ".jpeg";

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                SaveAsBitmap(this, saveFileDialog.FileName);
            }

            this.Close();

        }


1st try this code....again u get stuck on this process means ...
visit ....

http://msdn.microsoft.com/en-us/library/ytz20d80.aspx[^]
   
Comments
Deenuji 5-Dec-12 4:56am
   
just u change extension means i think that enough for this process.....
Screen screen = Screen.GetWorkingArea();
Bitmap bmp = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
g.Dispose();
bmp.Save(//path//);


more info @ Screen Class[^]
   
Do it the easy way - this saves the form Client area:
private Bitmap GetImage(Control c)
    {
    Bitmap bmp = new Bitmap(c.Width, c.Height);
    c.DrawToBitmap(bmp, new Rectangle(0, 0, c.Width, c.Height));
    return bmp;
    }
public void myButton_Click(object sender, EventArgs e)
    {
    Image im = GetImage(this);
    im.Save(@"D:\Temp\MyForm.jpg", ImageFormat.Jpeg);
    }
   
Comments
siasalar 5-Dec-12 5:26am
   
Error 1 The name 'ImageFormat' does not exist in the current context
OriginalGriff 5-Dec-12 5:52am
   
When you get that message, put your cursor in the word. A small blue line will appear at the beginning. hover the mouse over the line, and open the drop-down that appears. It will provide you with options to correct the problem. In this case, by adding the line
using System.Drawing.Imaging;
for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900