WP7 - POST form with an image

前端 未结 3 1389
悲&欢浪女
悲&欢浪女 2020-12-28 10:33

I need to send an image from the Windows Phone 7 to some e-mail addresses. I use this class to submit text values to a PHP script, wich parses data and sends a formatted e-m

3条回答
  •  无人及你
    2020-12-28 11:13

    The above code works perfect. I just use a different method to convert the file to an array of bytes which works perfect with Audio

    public static class FileHelper
    {
        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;
            }
        }
    }
    

提交回复
热议问题