Windows phone文件上传

wang628962 2014-02-12 05:26:33
我在做WP8文件(比如图片)上传,代码如下,但是无法将获得的照片流转化为Byte[]数组,然后上传到服务器
我自己写的方法ImageToByte转化之后发现Byte[]中的每一项都为零,这个问题困扰我好长时间了,请WP的同仁们给点思路。

public void SendPhoto()
{

PhotoChooserTask photoChoose = new PhotoChooserTask();
photoChoose.Completed += ((s,e) =>
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(e.ChosenPhoto)
Image img = new Image();
img.Source = bi;
img.Stretch = Stretch.Fill;
HttpWebRequestFileUpload(e.ChosenPhoto); }
});
photoChoose.Show();
photoChoose.ShowCamera = true;
}

public void HttpWebRequestFileUpload(Stream str)
{
Uri uri = new Uri("http://app.12345.com/", UriKind.Absolute);
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
request.ContentType = "image/jpeg";
request.Method = "POST";
request.BeginGetRequestStream(ldelegate =>
{
HttpWebRequest webRequest = ldelegate.AsyncState as HttpWebRequest;
using (Stream stream = webRequest.EndGetRequestStrea(ldelegate))
{
byte[] imgBytes = ImageToByte(str);
stream.Write(imgBytes, 0,imgBytes.Length);
}
webRequest.BeginGetResponse(ResponseCallBack, webRequest);
}, request);
}

private byte[] ImageToByte(Stream stream) {
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}


...全文
227 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
一只熊猫 2014-02-14
  • 打赏
  • 举报
回复
http://code.msdn.microsoft.com/wpapps/Photo-Uploader-Background-f3188f5b
wang628962 2014-02-14
  • 打赏
  • 举报
回复
引用 2 楼 Going1981 的回复:
WP8开发者中心有一个上传文件的DEMO,Photo Uploader
能把链接发过来吗?
一只熊猫 2014-02-14
  • 打赏
  • 举报
回复
WP8开发者中心有一个上传文件的DEMO,Photo Uploader
wang628962 2014-02-14
  • 打赏
  • 举报
回复
这个没有人做过吗?请给点信息

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧