Click here to Skip to main content
16,013,581 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I'm trying convert but it dont handle: WriteableBitmap bmp = new WriteableBitmap((BitmapSource)myImage.Source)
C#
public string ImageToBase64(Image myImage)
        {
            byte[] data;
            WriteableBitmap bmp = new WriteableBitmap((BitmapSource)myImage.Source);

            using (MemoryStream stream = new MemoryStream())
            {
                bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
                data = new byte[stream.Length];
                // Read the entire file and then close it
                stream.Read(data, 0, data.Length);
                stream.Close();
            }
            string base64 = System.Convert.ToBase64String(data);
            return base64;
        }
Posted
Comments
Sergey Alexandrovich Kryukov 16-May-13 10:49am    
Why?!
—SA
askersuku 16-May-13 10:53am    
I dont know why.. it's: Invalid pointer in myImage.Source

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