从字节[]

时间:2018-10-10 12:48:47

标签: c# sql database image

我正在从数据库中检索图像,并且想要图像的真实URL,而不是字节数组格式。是否可以直接从数据库获取图像url /链接?还是我需要一个Blob存储并从那里获取URL?

我正在使用ASP.net和SQL。

这就是我想要对其进行格式化的方式(不必完全相同)

<img src="website/images/image36.png"/>

这是现在的样子,如果图像为4k,如果我尝试编辑源代码,因为它包含许多字符,它将使浏览器崩溃

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAMAAABrrFhUAAAAM1BMVEWxvsa7xs7CzNPM1drT2t/a4OTd4+fn6+7g5enW3eLFz9W/ydC0wcnP1924xMvJ0tjk6OzcN6J1AAAED0lEQVR4AezBgQAAAACAoP2pF6kCAAAAAAAAAAC4vbvLgV3FgQBcCYHiLzT7X+28XWkermbOSeLYMd8OqAA2Ust9u20PR0z8R44l1AYX+n5G/ot01oFPG7/I/yGd23dXn/h/yZ/MoBX+gVTxLTXzD+XQ8Rl75l+YAd+wRf6lvMO+fvKCMmDclnjJ3GHaj5cdMOzgDVKHUT3xFnOzu37PCfREek6gJ9JzAj2RrhNIvNkc9uufo2r44wMKzNj4iB+M6JnP2GDDyYckmND4mAALMp8zoF/ggyLU65NPar43ABmdbwCy+d4AZHS9AfR3Q5WPO6BZ4uNmh16DAqrZZ7CDZ3GihO77BJC7/hrgtQ4cFJH1XwFeLwEKadCpUUjQ3wX4vAVPCknQKVIKdJqUskGjTjG7/iLgsQxUijmhUaCY6LsKksl5FSRXABpR0OY9gAZ9uvcAGgWFFYA6K4BAQcV7AHEFoM4KoFBQdv4UIFcAaqwAVgArgBXACmAFsAJokaJigyqB4oLz9atKoPEVDVpkviJDicqXVOhQ+JICFTpf06HBztfsmmqg30pYSN+XQORr4gpgBbACWJfgKoOrEVqt8HoMrefwuyZfMaFF4CuC/rkRbgYJFAVXoL9rsEKPzhd0KHJQ3AFNBsUNqHJS2GlrjK6DEatjUtAcUGckikkDGoVMETlAq01/A2S/J57Q7Od9mtxwfgIkRgl1+D4DBbp1v5PUZOpAhnY7HxWgXvb0CBa/Bg84Hy7e4Hu8fAR8b4EGE4LPDSCwBRqMqAIlwOGTaA6Y0cSbQAdzxRIs6Zl322BKEzgArpqBCHOiwK9B/LRDDQZtk3epMKm6aAEFEjhgVtW/fv0JlA7XCRwwrjpfP3BqfgHo74kbzDu9BxB5RfUeQFgBmDe9B0DnAXReUmBd4yXReRtAwrrMa3bYVknXZ6BnXtVgWeFlucOugzdI3ef67SfQC2+SBgxqmbeZO6zpJ29VOkypkzebFXa0xAfkBhtaFBgmrFeNfFCsUK3XzIfl2qHVOCcFzHNAoz1STNyhzAiZonIY0GMvfEHZnX58XdtgL3xV2Z1+fA3bYC9Uouy+Pr6CbdAK1SkNQvovU6X863jeOCbVmscQ3vvOTkJNNCBVPKNmGpGrs+ULRFAzjcnVyfIFImiJRqWG60ahYWXgot+kafOHK0akeXHo//xKN0E/+BGlax+RqXEE5zb5IXOTXb/9BLZJek5gTComMIIk8YOS2PADrYLiUfG6BtIf/KjD+QYgh8UbQP5PCSY/awpMRdVtt34FCoxl7vy07vsEkLv8CbDWCmR+Wpbvgoz1QpUfV+VHQdpqBiM/Lpq+AwVuQX6efB9oqhds/Ly2AlgBrAD+3XB+Ca4yiMSPS/hv/wEp/tUncVv5oQAAAABJRU5ErkJggg=="/>

基本上,我正在寻找的是html图像元素的src,它不是怪异的格式,例如字节,base64等...

1 个答案:

答案 0 :(得分:1)

如果要显示imgage使用URL,则需要先将图像另存为文件。

var imgUrl = "data:image/png;base64,iVBORw0KG...";
var imageCoding = Convert.FromBase64String(imgUrl.Split(",")[1]);
System.IO.File.WriteAllBytes("yourImage.png", imageCoding);

<img src="yourImage.png">