さて、これが私が持っているものです:
選択/撮影された写真をサーバーにアップロードする数行のコード:
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
image1.Source = bmp;
BitmapImage bitmapImage = bmp;
var largest = Math.Max(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
var ratio = largest / 1024;
var width = bitmapImage.PixelWidth / ratio;
var height = bitmapImage.PixelHeight / ratio;
WriteableBitmap wb = new WriteableBitmap(bitmapImage);
Stream str = null;
wb.SaveJpeg(str, width, height, 0, 75);
byte[] sbytedata = ReadToEnd(str);
string s = EncodeTo64(sbytedata.ToString());
WebClient wc = new WebClient();
Uri u = new Uri("//something ;)//");
wc.OpenWriteCompleted+=new OpenWriteCompletedEventHandler(wc_OpenWriteCompleted);
wc.OpenWriteAsync(u, "POST", sbytedata);
そして..それは機能していません:例外-画面
また、ReadToEnd()関数が必要です。これがあります:
public static byte[] ReadToEnd(System.IO.Stream stream)
{
long originalPosition = stream.Position;
stream.Position = 0;
try
{
byte[] readBuffer = new byte[4096];
int totalBytesRead = 0;
int bytesRead;
while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
{
totalBytesRead += bytesRead;
if (totalBytesRead == readBuffer.Length)
{
int nextByte = stream.ReadByte();
if (nextByte != -1)
{
byte[] temp = new byte[readBuffer.Length * 2];
Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
readBuffer = temp;
totalBytesRead++;
}
}
}
byte[] buffer = readBuffer;
if (readBuffer.Length != totalBytesRead)
{
buffer = new byte[totalBytesRead];
Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
}
return buffer;
}
finally
{
stream.Position = originalPosition;
}
}
何か案は?