Convert Bitmap Image to byte array (Windows phone 8)

后端 未结 2 1567
轻奢々
轻奢々 2021-01-25 20:54

I am new to windows phone dev. My small app need a bytesarray from image (photo gallery). I tried many ways to convert, but it did not work fine.

here is my code:

<
2条回答
  •  囚心锁ツ
    2021-01-25 21:14

    for windows phone 8

    using System.IO;

    public static class FileToByteArray
    {
        public static byte[] Convert(string pngBmpFileName)
        {
            System.IO.FileStream fileStream = File.OpenRead(pngBmpFileName);
    
            using (MemoryStream memoryStream = new MemoryStream())
            {
                fileStream.CopyTo(memoryStream);
                return memoryStream.ToArray();
            }
        }
    }
    byte[] PasPhoto = FileToByteArray.Convert("Images/NicePhoto.png")
    

提交回复
热议问题