【发布时间】:2018-09-28 16:27:23
【问题描述】:
我有一个asp。网络表单应用程序,允许用户在图像按钮中显示图片。我的困境是我的用户拥有的图片非常庞大(7200 像素 x 4800 像素)。我希望能够在保持图像按钮大小相同的同时放大图片。 最简单的方法是什么?
此外,在上传文件控件找到其 URL 后,将显示图像
这是我的 .aspx 代码:
<div class="picontainer" style="width: 900px" >
<asp:ImageButton ID="pic" runat="server" OnClick="Image_Click" />
</div>
.css for div picontainer:
.picontainer {
max-height: 600px;
max-width: 900px;
overflow: scroll;
}
这就是我选择 ImageButton.ImageUrl 的方式:
string folderPath = Server.MapPath("~/Files/");
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
string filename = FileUploader.FileName;
FileUploader.SaveAs(folderPath + filename);
string ext = Path.GetExtension(filename);
if (ext ==".png" || ext==".jpg" || ext==".gif" || ext==".jpeg")
pic.ImageUrl = "~/Files/" + Path.GetFileName(FileUploader.FileName);
我尝试过的:
我已尝试从 Windows 窗体库中导入方法。
我还尝试将图片保存为位图,并尝试通过将位图的大小乘以缩放因子并输出新的位图来调整图片的大小。不知道在使用这个方法时如何设置新的 URL
【问题讨论】:
-
不是那么简单 - 在这里看一个完整的例子 -> codeproject.com/Articles/6620/…