在WCF中处理图像 [英] Working with images in WCF

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

问题描述

我有一个桌面应用程序,需要通过TCP协议上传/下载图像到服务计算机。



起初,我将图像存储在文件系统中,但我需要在MS SQL DB来比较哪个解决方案更好。图片数量超过五十万。我不知道照片的大小还有没有限制。



如果你这样做了,请写下你对这个问题的看法。

哪一个更快,更安全?这些照片中的哪一个更好?如果我将数据库存储在数据库中,是否需要将图像与我用于应用程序的所有其他表格分开存储,以及哪种类型的表现更好 - 数据库上的图像或varbinary?等等。



谢谢。

解决方案

微软研究院的一篇名为为Blob或不Blob


$ b经过大量的性能测试和分析,他们得出的结论是这样的:如果你的图片或者文档是这样的:b
$ b

  • 通常小于256K,将它们存储在数据库VARBINARY列中效率更高。如果您的图片或文档大小超过1 MB,请将其存储在

  • 这个文件系统是更高效的(并且使用SQL Server 2008的FILESTREAM属性,它们仍然处于事务控制和数据库的一部分之间),在这两者之间的
  • 它'如果你决定把你的照片放到一个SQL Server表中的话,我强烈建议使用单独的表格来存储这些图片 - 不要将员工照片存储在员工表格中 - 将他们保存在单独的表格中。这样一来,假设你并不总是需要选择雇员foto作为你的查询的一部分,那么Employee表可以保持精简并且意味着高效。



    对于文件组,请查看文件和文件组体系结构。基本上,您可以从一开始就为大数据结构创建一个单独的文件组的数据库,或者稍后添加一个额外的文件组。现在,只要你有一个新的表来创建需要存储VARCHAR(MAX)或VARBINARY(MAX)列的列,你可以指定这个文件组为大数据:

    pre $ code CREATE TABLE dbo.YourTable
    (....... define这里的字段......)
    ON数据 - 常规数据的基本数据文件组
    TEXTIMAGE_ON LARGE_DATA - 大块数据的文件组

    查看关于文件组的MSDN介绍,并使用它!

    I have a desktop application that needs to upload/download images to/from service computer over TCP Protocol.

    At first, I stored images in file system, but I need to in MS SQL DB to compare which solution is better. Number of images is over half a million. I don't know yet will there be any limitation on size of a photo.

    If you have done smth like that, please, write what your opinion upon this question.

    Which one is faster, more safe? Which of them works better with this number of photos? If I'll store on DB, do I need to store images apart from all other tables which I use for my application and which type works better - image or varbinary on DB?..and so on.

    Thank you.

    解决方案

    There's a really good paper by Microsoft Research called To Blob or Not To Blob.

    Their conclusion after a large number of performance tests and analysis is this:

    • if your pictures or document are typically below 256K in size, storing them in a database VARBINARY column is more efficient

    • if your pictures or document are typically over 1 MB in size, storing them in the filesystem is more efficient (and with SQL Server 2008's FILESTREAM attribute, they're still under transactional control and part of the database)

    • in between those two, it's a bit of a toss-up depending on your use

    If you decide to put your pictures into a SQL Server table, I would strongly recommend using a separate table for storing those pictures - do not store the employee foto in the employee table - keep them in a separate table. That way, the Employee table can stay lean and mean and very efficient, assuming you don't always need to select the employee foto, too, as part of your queries.

    For filegroups, check out Files and Filegroup Architecture for an intro. Basically, you would either create your database with a separate filegroup for large data structures right from the beginning, or add an additional filegroup later. Let's call it "LARGE_DATA".

    Now, whenever you have a new table to create which needs to store VARCHAR(MAX) or VARBINARY(MAX) columns, you can specify this file group for the large data:

     CREATE TABLE dbo.YourTable
         (....... define the fields here ......)
         ON Data                   -- the basic "Data" filegroup for the regular data
         TEXTIMAGE_ON LARGE_DATA   -- the filegroup for large chunks of data
    

    Check out the MSDN intro on filegroups, and play around with it!

    这篇关于在WCF中处理图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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