image stream to base64 string in WP7

邮差的信 提交于 2019-12-12 01:32:25

问题


in my wp7 application i am selecting image from media library and i want to get base64 string of that image because i am sending it to my wcf service to create image on server. the code for getting base64 string is as follows:

void taskToChoosePhoto_Completed(object sender, PhotoResult e)
{
    if (e.TaskResult == TaskResult.OK)
    {
        fileName = e.OriginalFileName;
        selectedPhoto = PictureDecoder.DecodeJpeg(e.ChosenPhoto);
        imgSelected.Source = selectedPhoto;
        int[] p = selectedPhoto.Pixels;
        int len = p.Length * 4;
        result = new byte[len]; // ARGB

        Buffer.BlockCopy(p, 0, result, 0, len);
        base64 = System.Convert.ToBase64String(result);
    }
}  

but at server this code creates image file but in the format is invalid. I cross validated the base64 string but i think app is giving wrong base64string what could be the reason please help to find out the problem.


回答1:


You are sending base64-encoded pixels on the server. I'm not sure that this is what you need. How about converting Stream to the base64 string?

var memoryStream = new MemoryStream();
e.ChosenPhoto.CopyTo(memoryStream);
byte[] result = memoryStream.ToArray();
base64 = System.Convert.ToBase64String(result);


来源:https://stackoverflow.com/questions/10429700/image-stream-to-base64-string-in-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!