从Sql Server中检索图像 [英] Retreive Image from Sql Server

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

问题描述





我将图像上传到Sql Server



图像尺寸为1200像素高度和950像素宽度



我想要检索250像素高度和150像素宽度的相同图像





我是怎么做的请帮帮我

解决方案

这是一个有两个答案的问题,首先是从中访问图像SQL(以二进制格式存在)然后使用任何代码隐藏语言(如Visual C#或您正在使用的任何其他语言)调整图像大小。这些语言暴露了许多不同的方法



例如,您可以简单地转换并将图像转换为位图以处理其图形。要了解有关将图像从图像转换为位图的更多信息,请阅读来自OriginalGriff的此答案 [ ^ ]然后,您可以使用以下代码更改图像的宽度和高度。



  //  创建具有一定宽度和高度的位图对象 
位图newImage = new 位图(newWidth,newHeight);
// 从该位图创建图形对象
使用(Graphics gr = Graphics.FromImage(newImage))
{
// 为其添加一些属性
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
// 现在在屏幕上绘制图像,或者将其保存在某处。
gr.DrawImage(srcImage, new 矩形( 0 0 ,newWidth,newHeight));
}





以上代码来自此场外答案 [ ^ ]。


Hi

I upload a Image into Sql Server

Image Size is 1200 px Height and 950 px width

I want to retrieve same Image in the Size of 250 Px height and 150 px width


How i do this Please Help me out

解决方案

This is a question with two answers, first is to access the image from the SQL (which in there is in binary format) and then resize the image using any code-behind language like Visual C# or any other that you're using. These languages expose many different methods.

For example, you can simply convert and image to bitmap to work on its graphics. To learn more on converting an image from Image to Bitmap, read this answer from OriginalGriff[^] Then you can use the following code to change the width and height of the image.

// create the bitmap object with some width and height
Bitmap newImage = new Bitmap(newWidth, newHeight);
// create the graphics objects, from that bitmap
using (Graphics gr = Graphics.FromImage(newImage))
{
    // add some properties to it
    gr.SmoothingMode = SmoothingMode.HighQuality;
    gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
    gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
    // now draw the image on screen, or, save it somewhere.
    gr.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));
}



Above code was from this answer off-site[^].


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

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