【问题标题】:How to set imageurl and get image height and width dynamiclly in C#如何在 C# 中设置图像 url 并动态获取图像高度和宽度
【发布时间】:2016-01-20 07:23:11
【问题描述】:

这是我要设置图片网址并动态查找该图片的高度和宽度的图片。

<asp:Image ID="imgLogo" runat="server"/>

//分配图片路径。

string Path= Server.MapPath("~/Images/testImage.jpg")
System.Drawing.Bitmap img = new System.Drawing.Bitmap(Path);

//获取图像的高度和宽度。

int height=0, width=0;
height = img.Height;
width = img.Width;

【问题讨论】:

  • 您的问题是什么?这段代码有什么问题?
  • 您遇到了什么问题或错误?

标签: c# asp.net image path


【解决方案1】:

如果我们特别要求编译器将值转换为另一种数据类型,则必须使用显式转换。

string Path= Server.MapPath("~/Images/testImage.jpg")
System.Drawing.Bitmap img = new System.Drawing.Bitmap(Path);

int height = (int)img.Height;
int width = (int)img.Width;

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    相关资源
    最近更新 更多