简体   繁体   English

如何在C#中设置imageurl并动态获取图像的高度和宽度

[英]How to set imageurl and get image height and width dynamiclly in C#

Here is the image which i want to set image url and find the height and width of this image dynamically. 这是我要设置图像网址并动态查找此图像的高度和宽度的图像。

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

//Assign the image path. //分配图像路径。

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

//Get the image height and width. //获取图像的高度和宽度。

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

You have to use explicit conversion were we specifically ask the compiler to convert the value into another data type. 如果我们明确要求编译器将值转换为另一种数据类型,则必须使用显式转换。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM