tags:

views:

51

answers:

2

hi

i have Picturebox control that contain any picture - on my form

how i can save this picture ?

in Windows-CE C#

thank's in advance

A: 

Like this:

pictureBox.Image.Save(path, ImageFormat.Bmp);
SLaks
i got error: No overload for method 'Save' takes '1' arguments
Gold
Add `ImageFormat.Bmp`.
SLaks
@Gold: seriously, you couldn't figure that out?
ctacke
i got NullReferenceException
Gold
Does the PictureBox have a picture?
SLaks
you are right !! i only paint on the PictureBox... how to save this paint on picture box ?
Gold
You need to maintain a `Bitmap` object and draw everything on the `Bitmap` in addition to the `PictureBox`.
SLaks
How, exeactly, are painting into the picturebox? A little code works wonders for our understanding
ctacke
A: 

Well you've not given us much to go on at all, but I decided to try anyway. This works fine for me:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
        }

        Bitmap m_cache;

        void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (m_cache == null)
            {
                m_cache = new Bitmap(pictureBox1.Width, pictureBox1.Height);
                var g = Graphics.FromImage(m_cache);
                g.FillRectangle(new SolidBrush(Color.White), 
                                0, 0, m_cache.Width, m_cache.Height);
                g.DrawString("Hello World", this.Font, 
                             new SolidBrush(Color.Black), 0, 0);
            }

            e.Graphics.DrawImage(m_cache, 0, 0);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_cache.Save("\\myimage.jpg", ImageFormat.Jpeg);
        }
    }

pictureBox1 is a PictureBox on Form1.

If this doesn't point you in the right direction, then you really need to post some code.

ctacke