图像流到WP7中的base64字符串 [英] image stream to base64 string in WP7
问题描述
在我的wp7应用程序中,我正在从媒体库中选择图像,我想获取该图像的base64字符串,因为我将其发送到wcf服务以在服务器上创建图像.获取base64字符串的代码如下:
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);
}
}
但是在服务器上,此代码创建了图像文件,但格式无效.我交叉验证了base64字符串,但我认为应用程序给出了错误的base64string,这可能是请帮助查找问题的原因.
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.
推荐答案
您正在服务器上发送base64编码的像素.我不确定这是否是您所需要的.如何将Stream
转换为base64字符串?
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);
这篇关于图像流到WP7中的base64字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!