locked
Converting a photo taken with the camera to a base64 string

    Question

  • Hi,

    After taking a photo with the Camera in Windows 8.1 I would like to convert the image to an base64 string.

    I have seen enough samples and code in different forums but the issue is with the namespace and they are not supported in Windows 8.1 and the code does not compile at all.

    I would like to know the exact namespace and code to make it work without giving compilation errors.

    Any hints or help would be greatly appreciated.

    Thanks,

    Rajesh.

    Tuesday, July 08, 2014 5:25 AM

Answers

All replies

  • Which part of the problem are you having trouble with? It will help us help you if you can explain in more detail what you are doing.

    Once you have a buffer with your bitmap file data in it you can use http://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.110).aspx to convert it to a base64 string.

    Tuesday, July 08, 2014 6:20 AM
    Owner
  • Alternatively to convert from IBuffer, the Window Runtime API can be used. This is in Windows.Security.Cryptography

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.cryptographicbuffer.aspx

    string s = CryptographicBuffer.EncodeToBase64String(buffer);

    Tuesday, July 08, 2014 6:43 AM
  • Hi Mr. Rob Caplan,

    Thanks a lot for your reply. My issue is whatever code I found in different forums would give the error about a missing namespace.

    And I went through this link that you gave earlier. Though it says Supported in Windows 8, when I copy this code in my Windows Store XAML application I am getting this error

    Error 1 The type or namespace name 'FileStream' does not exist in the namespace 'System.IO' (are you missing an assembly reference?)

    What is the reason for this. and when a red squiggly is displayed, Intellisense helps to fill up the missing reference but it does not help any further.

    Thanks,

    Rajesh

    Tuesday, July 08, 2014 6:46 AM
  • FileStream does not exist in the System.IO namespace, so you are not missing an assembly reference.

    For file IO there are some classes in the Window Runtime API. FileIO in the Windows.Storage namespace would enable you to read the contents of a specified file and return a buffer.

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.storage.fileio.readbufferasync.aspx


    Tuesday, July 08, 2014 7:16 AM