压缩并将图片添加到数据库 [英] Compress and add pictures to the database

查看:235
本文介绍了压缩并将图片添加到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用以下方式允许用户添加图片。数据库。

Hi,
I am using following way to allow users to add pics. to the database.

Dim vrPicHolder As Byte()
The save commands follow
       OpenFileDialog.ShowDialog()
        vrPicHolder = IO.File.ReadAllBytes(OpenFileDialog.FileName)
        Dim drPic As DataRow
        drPic = DsPic.tblPicTest.NewRow
        drPic.Item("Picture") = vrPicHolder
        DsPic.tblPicTest.Rows.Add(drPic)
     taPic.Update(DsPic.tblPicTest)





问题是图片大小没有限制这里。通常使用添加图片。超过2Mb。这使得DB非常沉重。

有没有办法自动压缩文件,无论用户选择图片的大小。当保存时,我的应用程序可以将其压缩到几百kbs(可能低于400 kb)?

我希望它自动完成,而不是强迫用户这样做。

谢谢



The problem is there is no limit on size of picture here. Normally uses add pics. with over 2Mb. which makes the DB very heavy.
Is there a way to auto-compress the files, no matter what size user is selecting pic. of, when saved, my application could compress it to a few hundred kbs (may be under 400 kb)?
I want it to be done automatically, not to force users to do it.
Thanks

推荐答案

没有。

问题是大多数图像格式已经使用压缩 - 而且它们非常好在它 - 所以不能保证你做的任何事情都会明显减少数据大小(并且在某些情况下可能会增加它:想想当你压缩zip文件时会发生什么)。由于你无法控制用户使用的图像格式......



老实说,我不会将图像存储在我的数据库中 - 除了缩略图 - 我将图像存储在磁盘上,并将图像的路径存储在数据库中。
No.
The problem is that most image formats already use compression - and they are pretty damn good at it - so there is no guarantee that whatever you do will appreciably reduce the data size (and may in some cases increase it: think about what happens when you zip a zip file). And since you can't control what image format your users are using...

To be honest, I wouldn't store images in my DB anyway - except maybe thumbnails - I'd store the image on disk, and store the path to the image in the DB.


如果您正在处理尚未压缩的图像,则压缩它们是可行的。另一方面,如果你正在处理已经压缩的图像(例如jpeg,如 CHill60 所建议的那样),那么压缩它们将不会节省空间。

替代方案可以如果可接受,则存储较低分辨率(例如,具有较小颜色深度和较小尺寸)图像。通过重采样技术,您通常可以避免严重的质量损失。
If you are dealing with not already compressed images, then compressing them is viable. On the other hand, if you are dealing with already compressed images (e.g. jpeg, as already suggested by CHill60) then compressing them wouldn't save space.
An alternative could be, if acceptable, to store lower resolution (e.g. with smaller color depth and reduced size) images. With resampling techniques you could usually avoid severe quality losses.


这篇关于压缩并将图片添加到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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