我有一个base64 image
,我必须将其旋转,编码并再次保存在服务器上。
这是我的代码:
Function Rotate As Boolean(ByVal encoded As String)
Dim decoded, decoded2 As String
Dim ms As MemoryStream
Dim img As Bitmap
decoded = Convert.FromBase64String(encoded)
ms = New MemoryStream(decoded)
img = Image.FromStream(ms)
img.RotateFlip(RotateFlipType.Rotate90FlipNone)
img.Save(ms, Imaging.ImageFormat.Png)
decoded2 = ms.ToArray
Return decoded2.SequenceEqual(decoded)
End Function
尝试
Rotate("iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAY1BMVEX6wRP////+7r394Y36xib//fn+7br/+er834f81Fr97Lf7yC382Gv95Z36xB381F3++ef7zUD70VD834T83Hv94pL956T7yjf+8Mf82nP+9dn+9tz//PP96ar812f7zkb+8s8c6RSAAAABJElEQVRIie2T2XKEIBBFuYoC6iC4REedJP//lWGZmlRSJctDloe5L01BH6pvNxDy1G9reslKpwVwzQHkBlRvOcRyAIrmED2AIi1V160NsyF4Sn6roFz1qyFEAmBvrjpLMoC1CQQ3BC5mMZj4nlKUMB3Calo03smoFjMFKE1IY+JrMFVLF2TjjdAdOJZAvmSs9NO6G9FVeBqTvfim7bL3Rjo0oXmXlb0YhW3/sjsjQ9ACoZw5ZOskoTVSnqy8bg5hIyUl5mi+lVgdclyWWD2Pd6BvzkwVed8crCh7T7Wz6VLslxbw1ddcGEpOe2hkVt6tl2q4iH84KnijPqHxPNOcPtat4LUfxvD14AzwVF8WTGYAsQO/j2/6B0C2hx8GTvVHwFPn+gCZFgncZtkleAAAAABJRU5ErkJggg==")
问题是decoded
和decoded2
是相同的。如果我使用img.Save(ms, Imaging.ImageFormt.Png)
更改行img.Save("C:\test\test.png", Imaging.ImageFormt.Png)
,则会正确旋转磁盘上的图像。为什么呢?