在SQL中创建图像缩略图 [英] Create thumbnail of image in SQL

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

问题描述

您好,

i我正在使用以下方法为存储在SQL表中的图像创建缩略图

Hello,
i am using following method to create a thumbnail for image stored in SQL table

public static byte[] MakeThumbnail(byte[] myImage, int thumbWidth, int thumbHeight)
{
    using (MemoryStream ms = new MemoryStream())
    using (Image thumbnail = Image.FromStream(new MemoryStream(myImage)).GetThumbnailImage(thumbWidth, thumbHeight, null, new IntPtr()))
    {
        thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        return ms.ToArray();
    }
}



创建缩略图的原因:创建小尺寸图像并减少下载/复制时间/



我可以创建缩略图I SQL(类似于C#中的Image.GetThumbnailImage)

出于某种原因,我想在SQL上压缩图像。有没有办法呢?


Reason to create thumbnail : create small size image and reduce download/copy time/

Can i create thumbnail I SQL (something similar to Image.GetThumbnailImage in C#)
For some reason i want to compress images at SQL. Is there any way to it ?

推荐答案

没有。 SQL不理解图像 - 就它而言,它们只是字节流。

创建缩略图意味着不仅要了解图像尺寸,还要对像素数据进行一些复杂的处理 - 你必须正确理解图像数据才能做到。
No. SQL does not understand images - they are just streams of bytes as far as it is concerned.
Creating a thumbnail means understanding not only the image dimensions, but doing some complex processing on the pixel data as well - you have to "understand" image data properly in order to do it.


如果你正在使用MS SQL Server> = 2008,你可以试试运气创建CLR存储过程 [ ^ ]。另一个有用的资源是 CLR存储过程 [ ^ ]。

当然,这意味着图像将在缩略图之前传输到SQL服务器。这将为您的网络和SQL Server带来更多负载。不确定这是否是人们想要发生的事情。 :)

警告!:MSDN写道:



注意:默认情况下,SQL Server执行CLR代码的能力是关闭的。您可以创建,更改和删除引用托管代码模块的数据库对象,但这些引用不会在SQL Server中执行,除非使用sp_configure启用了clr enabled选项(Transact-SQL)。



问候,



- Manfred
If you're using MS SQL Server >= 2008 you could try your luck with Creating CLR Stored Procedures[^]. Another useful resource is CLR Stored Procedures[^].
It will mean of course that the images will be transferred to the SQL server before being thumbnailed. This will put more load on your network as well as the SQL Server. Not sure if this is what one would want to happen. :)
Caveat!: MSDN writes:

"Note: The ability of SQL Server to execute CLR code is off by default. You can create, alter, and drop database objects that reference managed code modules, but these references will not execute in SQL Server unless the clr enabled Option is enabled by using sp_configure (Transact-SQL)."

Regards,

— Manfred


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

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