[英]How to enlarge image to normal size in ASP.NET 2.0
如果用户上传一张 300 像素 x 200 像素的图片,该图像在我的 static 150 像素 x 150 像素图像框中会看起来很有趣。 知道如何显示图像以使其不会模糊吗?
此外,当用户单击 150 像素 x 150 像素的图像时,如何在屏幕上显示某种形式的弹出窗口,显示数据库中图片的实际大小。
注意:我不希望图像 static 大小增加,因为这会完全弄乱我的页面布局和外观。 它必须是某种形式的弹出窗口或其他东西。 我以前看过的东西我觉得真的很酷。 用户单击小图像,然后在屏幕中间出现一个带有图片实际大小的弹出窗口,页面上的所有内容都被禁用,直到用户单击关闭按钮。 这可以在 ASP.NET 2.0 中完成吗? 或者类似的东西?
问候艾蒂安
使用固定宽度/高度的缩略图。
您可以即时调整实际图像(存储在数据库中)的大小。
因此,您的缩略图大小始终为 150 像素 x 150 像素。 存储在数据库中的实际图像(宽度/高度)会有所不同。
您首先显示调整大小的缩略图列表,当您单击缩略图项目时,这些缩略图会在弹出窗口 window 中显示完整图像。
“缩略图”图像的代码:
byte[] getResizedImage(String path, int width, int height)
{
try
{
Bitmap imgIn = new Bitmap(path);
//Scale
double y = imgIn.Height;
double x = imgIn.Width;
double factor = 1;
if (width > 0)
{
factor = width / x;
}
else if (height > 0)
{
factor = height / y;
}
System.IO.MemoryStream outStream = new System.IO.MemoryStream();
Bitmap imgOut = new Bitmap((int)(x * factor), (int)(y * factor));
Graphics g = Graphics.FromImage(imgOut);
g.Clear(Color.White);
g.DrawImage(imgIn, new Rectangle(0, 0, (int)(factor * x), (int)(factor * y)), new Rectangle(0, 0, (int)x, (int)y), GraphicsUnit.Pixel);
imgOut.Save(outStream, ImageFormat.Jpeg);
return outStream.ToArray();
}
catch (Exception)
{
...
}
}
此示例使用 web 服务器文件系统上的 .jpg 图像,但可以进行调整以适应数据库中存储的任何图像/类型。
莫伊布莱。
编辑:固定图像格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.