将图像转换为二进制

将图像转换为二进制

问题描述:

大家好,

我有一个图像路径和数据库中包含图像列的表格

我如何获取图像并将其转换为二进制文件,所以我可以将它存储在数据库中吗?

Hello all,
I have a image path and a table in database that contains image column
How can I get the image and convert it to binary, so I can store it in database??

参考:

1. C#从数据库保存和加载图像 [ ^ ]

2. 使用BinaryFormatter将类分类/反序列化为SQL Server图像列 [ ^ ]
Refer:
1. C# Save and Load Image from Database[^]
2. Serialize/Deserialize Classes into SQL Server Image Columns using the BinaryFormatter[^]


您可以使用File.ReadAllBytes [ ^ ]方法然后将它们存储在您的数据库中。

You can read the bytes from the file using the File.ReadAllBytes[^] method and then store those in your database.
byte[] imageData = File.ReadAllBytes(filePath);
// store imageData in database

C#中的图像:保存,调整大小并转换为二进制 [ ^ ]



http://startcoding.in/2012/03/06/save-retrieve-image-from-binary-data-database-asp -net / [ ^ ]