C#:将图像保存到DB中 [英] C# : Saving an Image into DB

查看:125
本文介绍了C#:将图像保存到DB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以就如何在C#中将图像文件保存到数据库中给出一些建议吗?
我将保存很多图像,那么减少需要的空间
的最佳方法是什么?
我目前正在DB中使用varbinary(max)字段。

Can someone give me some advice on how to save an image file into DB in C#? I will be saving a lot of images so what's the best way to reduce the space it will be needing? I'm currently using varbinary(max) field in DB.

谢谢!

推荐答案

如果你必须将实际文件存储在SQL中,那么请确保对图像大小设置一些限制,并确保正确规划数据库大小 - 有多少图像和大小期待?

If you MUST store the actual file in SQL then make sure you put some restrictions around the size of the image and make sure you properly plan the database sizing - how many images and of what size are you expecting?

如果你必须将它存储在SQL中,我的首选项是自动将它放在自己的SQL数据库中。这样,我遇到这些图像的任何性能问题都不会影响我的数据库的其余部分。

If you must store it in SQL my preferences is to automatically have it sitting in its own SQL database. This way any performance issues I run into with these images is not affecting the rest of my database.

现在,如果你不必将图像存储在SQL数据库中那么我认为这只是要求用Azure Blob存储完成。去看一下它 - 它会在一个非常有效的系统中为你提供你想要的东西。

NOW, if you do not have to store the images in a SQL database then I think this is just calling out to be done with Azure Blob Storage. Go take a look at it - it will give you what you want in a very efficient system.

如果你不能使用Azure那么你应该把一个可以处理的类放在一起读取/写入/查找图像到文件系统。保存到文件系统(正确完成)比保存到SQL要好得多。

If you cannot use Azure then you should put together a class that will handle reading/writing/lookup of images to a file system. Saving to the file system (done properly) will work much better than saving to SQL.

这篇关于C#:将图像保存到DB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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