Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.Net:在内存中旋转base64图像_Vb.net_Image - Fatal编程技术网

VB.Net:在内存中旋转base64图像

VB.Net:在内存中旋转base64图像,vb.net,image,Vb.net,Image,我有一个base64图像,我必须将其旋转、编码并再次保存在服务器上。 这是我的代码: 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 Memo

我有一个
base64图像
,我必须将其旋转、编码并再次保存在服务器上。 这是我的代码:

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”)
,磁盘上的图像将正确旋转。为什么?

推测:在
FromStream
之后,您不会重置内存流的位置,因此
Save(ms…)
可能只是将旋转后的图像附加到流中。您是否尝试过使用不同(新)的MemoryStream?它还可以提高代码的可读性(
msSource
msRotated
ms
更明确)。顺便说一句,
decoded2=ms.ToArray
不正确-您试图将数组分配给字符串变量。您的意思是写
decoded2=Convert.tobase64字符串(ms.ToArray())
?如果您还没有这样做,请启用
Option Explicit
-它很容易捕获这些类型的错误。我尝试使用不同的内存流,得到相同的结果。关于第二个错误,只是一个复制错误。正确的声明是Dim decoded(),decoded2()作为字节。您可以提供一个(包括演示问题的代码中的一个小的Base64编码图像)?我已经编辑了我的代码