2
            //convert photo to baos
            var memoryStream = new System.IO.MemoryStream();
            e.ChosenPhoto.CopyTo(memoryStream);
            //string baos = memoryStream.ToString();
            byte[] result = memoryStream.ToArray();
            String base64 = System.Convert.ToBase64String(result);
            String post_data = "&image=" + base64;
            ...
            wc.UploadStringAsync(imgur_api,"POST",post_data);  

このコードを使用して、WebClient を使用して画像を Imgur API v3 にアップロードしています。選択されている画像は、Windows Phone 7.1 エミュレーターによって提供される 7 枚の写真のいずれか、またはシミュレートされたカメラ画像です。画像を読み込もうとすると、大部分が灰色の破損した混乱です。base64 を適切に生成していますか、または byte[] と base64 を作成する前に、最初に画像のビットマップをレンダリングする必要がありますか?

前もって感謝します!

4

2 に答える 2

0

私はこれを使います

 private void PhotoChooserTaskCompleted(object sender, PhotoResult e)
    {
        if (e.TaskResult != TaskResult.OK) return;
        var bimg = new BitmapImage();
        bimg.SetSource(e.ChosenPhoto);
        var sbytedata = ReadToEnd(e.ChosenPhoto);
    }

 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;
        }
    }

そしてサーバーにアップロードbyte[]します。それが助けになることを願っています

于 2013-04-22T06:43:02.623 に答える