编码为base64图像旋转90度之后

问题描述 投票:2回答:1

在我的应用中,我正在将图像上传到服务器。我对WP 8.1中的图像进行编码并将其发送到服务器。发送和接收工作正常,但是图像有问题。我不知道为什么,但是在解码后我上传了人像拍摄的图像时,该图像旋转了90度。风景图像不错,但人像旋转。这是我的编码和解码代码

编码:

 private async Task<string> StorageFileToBase64(StorageFile file)
        {
            string Base64String = "";

            if (file != null)
            {
                IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);
                var reader = new DataReader(fileStream.GetInputStreamAt(0));
                await reader.LoadAsync((uint)fileStream.Size);
                byte[] byteArray = new byte[fileStream.Size];
                reader.ReadBytes(byteArray);
                Base64String = Convert.ToBase64String(byteArray);
            }

            return Base64String;
        }

解码服务器上的图像

public void ShowImg(string b64)
            {
                byte[] imageBytes = Convert.FromBase64String(b64);
                // Convert byte[] to Image
                var ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

                Image image = Image.FromStream(ms, true);


                f.pictureBox1.Image = image;

            }
c# windows image windows-phone-8.1 base64
1个回答
0
投票
string startExpression = "data:image/png;base64,";
using (var ms = new MemoryStream())
{
   ms.Flush();       
   System.Drawing.Image imageIn = System.Drawing.Image.FromFile(fileName);  
   ms.Position = 0;                              
   imageIn.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipX);
   imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
   var bytes= ms.ToArray();
   string fileBase = Convert.ToBase64String(bytes); 
   var base64= startExpression + fileBase;
   imageIn.Dispose();
   ms.Dispose();
} 
© www.soinside.com 2019 - 2024. All rights reserved.