我想从数据库中检索图像,并根据用户需要裁剪它

问题描述 投票:0回答:4

protected void Page_Load(object sender, EventArgs e) { MemoryStream stream = new MemoryStream(); SqlConnection connection = new SqlConnection(@"Data Source=localhost;Initial Catalog=card;User Id=sa;Password=db2admin;"); try { connection.Open(); SqlCommand command = new SqlCommand("select Photo from iffcar", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Jpeg); } catch (Exception ee) { connection.Close(); stream.Close(); HttpContext.Current.Response.Write(ee.Message); } }

检索的图像显示在浏览器内部。

现在,我一直坚持如何裁剪此图像,我想允许用户从数据库中获取的图像并将裁剪图像存储在Crystal Report中。

这可能吗?如果是这样的教程或帮助,可以指导我达到我的最终要求。请帮助我了解如何进行查询

查看GDI+库以及System.Drawing名称空间。您也可以使用Windows成像组件。

c# asp.net image-processing
4个回答
1
投票

填写在“ s”中,然后尝试以下操作: connection.Open(); SqlCommand command = new SqlCommand("select Photo from iffcar", connection); byte[] image = (byte[])command.ExecuteScalar(); stream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(stream); int croppedWidth = ??, croppedHeight = ??, cropOffsetX = ??, cropOffsetY = ??; var croppedBitmap = new Bitmap(croppedWidth, croppedHeight); var graphics = Graphics.FromImage(croppedBitmap); graphics.DrawImage(bitmap, -cropOffsetX, -cropOffsetY, bitmap.Width, bitmap .Height); Response.ContentType = "image/gif"; croppedBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);


0
投票

yo可以通过位图类轻松地调整图像大小,查看此构造函数-Ihttp://msdn.microsoft.com/en-us/library/0wh0045z.aspx

    

0
投票

hello到了 我是Konoha的Hinata Hyuga


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.