[英]Send image in WP7
我需要使用參數“access_token”和“photo”(我需要發送的圖像)將圖像(jpeg、png 等)發送到服務器。
..if (e.TaskResult == TaskResult.OK) {
BitmapImage image = new BitmapImage();
image.SetSource(e.ChosenPhoto);
// foto.Source = image;
Byte[] byteArray;
using (MemoryStream ms = new MemoryStream()) {
WriteableBitmap btmMap = new WriteableBitmap(image);
// write an image into the stream
System.Windows.Media.Imaging.Extensions.SaveJpeg(btmMap, ms, image.PixelWidth, image.PixelHeight, 0, 100);
byteArray = ms.ToArray();
}
((App)Application.Current).get_data(uploadServer + "?photo=" + *HOW I CAN SEND BYTE ARRAY?* + "&access_token=" + ((App)Application.Current).access_token
//
public void get_data(string url,Action<string> qw) {
try {
var request = (HttpWebRequest)WebRequest.Create(
new Uri(url));
request.BeginGetResponse(r => {
var httpRequest = (HttpWebRequest)r.AsyncState;
var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
HttpStatusCode st = httpResponse.StatusCode;
if (st == HttpStatusCode.NotFound) {
ToastPrompt toast = new ToastPrompt();
toast.TextOrientation = System.Windows.Controls.Orientation.Vertical;
toast.Message = "Ошибка соединения с сервером";
toast.MillisecondsUntilHidden = 2000;
toast.Show();
} else
using (var reader = new StreamReader(httpResponse.GetResponseStream())) {
var response = reader.ReadToEnd();
Deployment.Current.Dispatcher.BeginInvoke(new Action(() => {
qw(response);
}));
}
}, request);
} catch (WebException e) { }
}
您不能將圖像“獲取”到 URL(您試圖將數據發布到 URL 中,但您不能),您需要使用 POST 請求的OutputStream
來“發布”您的圖像。
Dictionary<string, object> data = new Dictionary<string, object>()
{
{"photo", byteArray},
};
PostSubmitter post = new PostSubmitter() { url = uploadServer, parameters = data };
post.Submit();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.