如何将Jpeg格式转换为二进制格式存储在Sql Server数据库中 [英] How Can I Convert Jpeg Format Into Binary Form To Store In Sql Server Database

查看:76
本文介绍了如何将Jpeg格式转换为二进制格式存储在Sql Server数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是parashuram

i想知道我想将jpg格式转换为二进制格式以存储在sql server表中作为列..

并在我的Windows应用程序中从二进制格式返回到jpg格式。



所以plz需要我的要求。

hi ,
this is parashuram
i would like to know that i want to convert jpg format into binary form to store in sql server table as a column..
and also retrieve back from binary to jpg format.in my windows application.

so plz do the needful to my requirement.

推荐答案

参考以下文章:

使用FileUpload控件将文件保存到SQL Server数据库 [ ^ ]
refer below article :
Save Files to SQL Server Database using FileUpload Control[^]


我假设你的意思是转换到一个字节数组,可以存储在SQL Server中的图像项中并从中检索吗?



I assume you mean to convert to a byte array which can be stored in and retrieved from an image item in SQL Server?

public static byte[] OpenImageToByteArray(Image image, ImageFormat format)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                image.Save(ms, format);
                return ms.ToArray();
            }
        }

 //Now write the result to SQL Server...





反向





And the reverse

//Get the value from SQL Server...

        public static Image OpenImageFromByteArray(byte[] image)
        {
            using (MemoryStream stream = new MemoryStream(image, true))
            {
                return Image.FromStream(value);
            }
        }


这篇关于如何将Jpeg格式转换为二进制格式存储在Sql Server数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆