qq113632
qq113632
2020-07-14 16:08
采纳率: 100%
浏览 234

C#如何将字节流数据显示为图片?

^Application^Octer-stream^Base64^„„直方图数据„„”,其中“Application”表示传送的是应用程序数据,“Octer-stream”表示数据为字节流类型, “Base64”表示位图数据的编码方式。

数据:^Application^Octer-stream^Base64^AAEBAgIDAwMEBAQEBQUFBAQEAwMDAgICAgICAgICAgEBAQEBAQEBAQEBAQEBAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=

  • 点赞
  • 收藏

3条回答 默认 最新

  • S2T11Enterprise
    Johan. 2020-07-23 14:27
    已采纳

    如果这个规则不变,可以通过 .Split('^')[4] 取出来转成 bytes 再转成图片。

    AAEBAgIDAwMEBAQEBQUFBAQEAwMDAgICAgICAgICAgEBAQEBAQEBAQEBAQEBAQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=

    但是我试过把这段转成图片,发现是失败的,那么很有可能这串字符串不是标准的 base64 字符串,或许需要解码。下面尝试转图片失败的过程。

    图片说明


    这里出使用一张 CSDN 的默认头像照片转成的 Base64 字符串,再转换成图片最后赋值给 pictureBox1 的代码
    图片说明

    https://oktools.net/image2base64

    这个网站可以在线把图片和 base64 之间互转。最后是转换成功的代码和 base64 信息

    var str = "^Application^Octer-stream^Base64^iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAYAAAA8AXHiAAAQBklEQVR4Ae2cPa8mORFG9+9utjEbkJFAQroBQiRESJsgBBIRIAhINkEiWUGAREBAAAHRReeuHqmmxnaX3bbbfsdBy/3hj7Lr+Knqfu/MZ7/5x3/fznHWoDcDn/Xu8PR3IIWBA9ZR7CER64B1wDpgnTC7T5g9ivWwYv3iz38dohhPb8ID1kNgA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d+XQJ5+pXBosjGQxgUhKkipxCI7p6egojHfqAWou3GmezH0noLYBS4ZGAJOS4Sycthpo2CNl8iFVIKncFSj5a3nFkqG2JM9Q7iNH5EochKIpgZ4FG+MAt5L6qL3MA5vtfHc83xIsLTQqlgOqdB+1EHCoG85XDmXzJw8h1zqoBzi04xBA9FsDUc7OXZJ0+cKXW4OFE3OOeYX7O+ZWAmxbsNjRrwBPaQ4onxy1W7klWOzkq+S35LCdnu0aErcE69VDoAd/x5C4HVivFgIjystGOqHw4n/TvbtAEUf4Hb/yNfOJvEXuFhK3UqzSTx694cHhjGc/R+izgj4tRICI2BUJ7bsl8tuAFU3Y7yoaTub7VPSnGr5nAV8EoFwdoIlAupNqbQNWRK0izik5twYoDx6ARZQnN34kd2TT3E0lZrXfAizUKucQe7/VsQAJGB6WluvIBrA26xywImq7i2ptAVbEWcDRAhbt/E83LUDZNhF7BZRKbI+020W1lgcrqlbRHS9HqrwT/ixM9hxQI+ojGyipXzPXWSGtdZzlwYru4qhTrDNJui0QPc95g7RjRc6ZQ0R1d1Ct5cGK7HycEUl+vXN7h0APZu3LBHOIzoN6rWoyo93SYEUXObrTLVgooQeh93XtZwg2CE6PbCagnQFI6xhLgxXZ8QoLkboWrBG5lQeTN0075tW5YImEQ/piQ7U6fnS7ZcGK5kwoD4t05TT7HBg9BKOua4FnLlGllsKNhqSl/2XBqtm1UQgFF32PAsn3G3n5kF2UUqFIOLT1W5w/ss2yYNnFzp0rDNaCNfJt0IPF74o5+1P3BVZ0Y0mxR0LS0veSYEVDgRY1Wl+O5FOAB2DUde1nB+aCI6Nz0uZqcf7INkuCFc1Lap0gsGYk7gKVsTRupNScalRYbUaCUtv3cmDVLKgmW5vH9PpdUPCUyto3Q6kwc4tusBWT+OXAikKiV3McEG0jxRj9YdSDpnEjpYWkZl7aZKuU/wfWRluJhua22QAAAABJRU5ErkJggg==";
    var bytes = Convert.FromBase64String(str.Split('^')[4]);            
    var ms = new MemoryStream(bytes);
    pictureBox1.Image = Image.FromStream(ms);
    
    点赞 评论
  • caozhy

    这个直接放在 img 里面应该就可以有图片,除非你的这一串不完整或者不合法。
    你可以对照下这个
    https://www.cnblogs.com/wilbur-wb/p/6709335.html
    看看其中的你的程序能否解码

    点赞 评论
  • weixin_49521838
    weixin_49521838 2020-07-20 17:27

    base64->字节流->文件流->图片对象

    点赞 评论

相关推荐