none
Convert Image File to Base64Binary RRS feed

  • Question

  • Does anybody know how to convert an image file to Base 64 using Excel VBA?  I am using Excel to save a chart as an image and then import it into OneNote.  OneNote apparently needs it in the form of a base64Binary to input as data.  This is actually a smaller part of a larger problem but I figured it would be better to break up my problem into smaller pieces.  However, anyone who is familiar with OneNote API and wants a challenge see http://social.msdn.microsoft.com/Forums/en-US/d93caf4a-3a09-4672-89cf-05e833e6e409/export-excel-chart-to-onenote?forum=officegeneral

    The code that I currently have is below; I tried to convert it from VB.net but it is not working correctly.  The line sd.Save errors. 

        Dim sd As Bitmap
                sd = "C:\Users\MyUserName\SkyDrive\Charts\" & ChartName & ".jpg"
                Dim imgStream As MemoryStream
                imgStream = New MemoryStream
                sd.Save imgStream, Imaging.ImageFormat.jpg

                imgStream.Close
                Dim byteArray As Byte
                byteArray = imgStream.ToArray()
                imgStream.Dispose

                'Convert the byte[] to base64 string for use to upload.
                Dim final As String
                final = Convert.ToBase64String(byteArray)

    Thursday, July 24, 2014 6:51 PM

Answers

All replies