如何在存储到datatbase之前压缩和检索图像 [英] How to compress and retrive image before storing in datatbase

查看:74
本文介绍了如何在存储到datatbase之前压缩和检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像存储在数据库中。它作为二进制数据存储在数据库中。我的数据库变得很重,因为我直接存储它。

帮我做些什么来减少数据库。

我不想将图像保存到文件夹中。

I am storing image in database . It store as binary data in database. My database become heavy as i store it directly.
Help me what to do to reduce database.
I don't want to save image in folder.

推荐答案

如果图像尚未压缩,您可以节省空间(例如, JPEG 图像已经压缩)。如果是你的情况,那么 System.IO.Compression [ ^ ]命名空间是你的朋友。
You may save space just if images aren't already compressed (for instance, JPEG images are already compressed). If it is your case then System.IO.Compression[^] namespace is your friend.


可能你不能 - 不会丢失细节或缩小图像大小。大多数图像格式已经使用有损或无损压缩技术进行了压缩,并且很难(甚至不可能)在不改变大小或丢弃数据的情况下进一步压缩数据 - 当然没有通用的这适用于所有图像解决方案。压缩图像甚至可以使它们变大,因为它增加了少量的减压开销!



我强烈建议你不要在你的数据库中存储图像 - a在大多数情况下,文件夹是一个更好的解决方案,即使你不想这样做!
Probably, you can't - not without losing detail or reducing the image size. Most images formats are already compressed using either a lossy or non-lossy compression technique, and it's hard (or even impossible) to compress the data further without changing the size or throwing away data - certainly there is no generic "this works for all images" solution. Compressing images may even make them larger as it adds a small amount of decompression overhead!

I'd strongly suggest that you don't store images in your DB - a folder is a much better solution in most cases, even if you don't want to do that!


这篇关于如何在存储到datatbase之前压缩和检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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