简体   繁体   中英

URI formats are not supported for properties height and width of image

I am trying to access height and width of an System.Drawing.Image .

Image image = Image.FromFile(PostedImage.ImageUrl.ToString());
int ActualWidth = image.Width;
int ActualHeight = image.Height;

I am getting error

URI formats are not supported.

How can this be done?

This means that you cannot sent a URL to Image.FromFile() You must pass a local path on disk.

To remedy this:

  • saving your image to a location on disk
  • load your image into a Stream of some kind, and use Image.FromStream()

my guess is that FromFile works on local files only. i would fetch the file using WebRequest and then create Image from stream.

You have to pass a path to a local file or one on a network drive.

If the string you give it is to a web resources, you have to first download it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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