C# .NET - convert picturebox.resourse to byte[] Array to send it to database

Asked By Rabeea Nasser on 13-Jun-13 06:57 AM
sorry i need help in converting image(picturebox.resourse) to byte array (byte[])  in wpf
id used this code : but it cannot resolve second line "Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);"
MemoryStream ms = new MemoryStream();
picturebox.Resources.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic_arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(pic_arr, 0, pic_arr.Length);


Please If You can help me I would be grateful.
Sathish S replied to Rabeea Nasser on 13-Jun-13 07:29 AM
try this

Image img = PictureBox1.Image;
byte[] arr;
using (MemoryStream ms = new MemoryStream())
{
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    arr =  ms.ToArray();
}
Rabeea Nasser replied to Sathish S on 13-Jun-13 07:43 AM
thanks but to access to the image in picturebox in wpf you have to use this 
picturebox.resourse
Rabeea Nasser replied to Rabeea Nasser on 13-Jun-13 04:32 PM
Thank For every body I solved

private void GetImage(byte[] pic)
        {
            byte[] data = (byte[])pic;
            MemoryStream strm = new MemoryStream();
            strm.Write(data, 0, data.Length);

            strm.Position = 0;

            System.Drawing.Image img = System.Drawing.Image.FromStream(strm);

            BitmapImage bi = new BitmapImage();

            bi.BeginInit();

            MemoryStream ms = new MemoryStream();

            img.Save(ms, ImageFormat.Bmp);

            ms.Seek(0, SeekOrigin.Begin);

            bi.StreamSource = ms;

            bi.EndInit();

            pbStuPic.Source = bi;






        }    we caled like this var bits = getJPGFromImageControl(pbStuPic.Source as BitmapImage);