将 SQL 服务器数据库中 base64 编码字符串中的图像保存为 png 文件
Save image from base64 encoded string in SQL Server database as a png file
我有一个 table 列,其中的字符串数据以 0xFFD8FFE000....
开头并以 FFD9
结尾。每行的开始和结束相似,但之间不同。
如果我检查图像周围生成的 HTML,我了解到它显示为 PNG。我的最终目标是将字符串转换为文件的脚本导出。我正在寻找信息,包括链接,以便在我的路上发送给我。
你有几个选择。所有这些都包含一些编码。 SQL 服务器没有将 base64 编码字符串导出为文件的内置方式。
但是你可以....
编写一个 CLR,它将从 TSQL / 数据库端执行此操作。您在 CLR 中需要的相关 C# 代码如下所示:
File.WriteAllBytes(@"c:\yourfile", Convert.FromBase64String(yourBase64String));
这是由 link 提供的:Base64 encoded string to file
或者编写一个快速控制台应用程序到 运行 遍历每一行并将其拉出。将上面相同的代码片段用于 C# 或 google 上记录的任何其他语言。另一种快速 google 搜索方法是:
public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}
致谢:http://www.dailycoding.com/Posts/convert_image_to_base64_string_and_base64_string_to_image.aspx
我有一个 table 列,其中的字符串数据以 0xFFD8FFE000....
开头并以 FFD9
结尾。每行的开始和结束相似,但之间不同。
如果我检查图像周围生成的 HTML,我了解到它显示为 PNG。我的最终目标是将字符串转换为文件的脚本导出。我正在寻找信息,包括链接,以便在我的路上发送给我。
你有几个选择。所有这些都包含一些编码。 SQL 服务器没有将 base64 编码字符串导出为文件的内置方式。
但是你可以....
编写一个 CLR,它将从 TSQL / 数据库端执行此操作。您在 CLR 中需要的相关 C# 代码如下所示:
File.WriteAllBytes(@"c:\yourfile", Convert.FromBase64String(yourBase64String));
这是由 link 提供的:Base64 encoded string to file
或者编写一个快速控制台应用程序到 运行 遍历每一行并将其拉出。将上面相同的代码片段用于 C# 或 google 上记录的任何其他语言。另一种快速 google 搜索方法是:
public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);
// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
return image;
}
致谢:http://www.dailycoding.com/Posts/convert_image_to_base64_string_and_base64_string_to_image.aspx