简体   繁体   中英

how to take image from physical path(local disc)

filename = Path.GetFileName(FileUpload.FileName);
HttpPostedFile pf = FileUpload.PostedFile;
System.Drawing.Image img2 = System.Drawing.Image.FromStream(pf.InputStream);

System.Drawing.Image bmp2 = img2.GetThumbnailImage(200, 210, null, IntPtr.Zero);

Imagename = objUser.UserID + filename;
Imagepath = "D:\\Shopy_Web_21-6-12\\Shopy\\Images" + Imagename;
bmp2.Save(Path.Combine(@"D:\Shopy_Web_21-6-12\Shopy\Images", Imagename));

I've converted the file upload in to two thumbnails and saved them locally, but now I need retrieve the image to display it on the user's profile. How can I get the image to display from where I've stored it?

You can create a virtual path in your application say: ..Images/ and save your images in that folder.

and after that use the below one to fetch the image URL:

string str = Server.MapPath("Images/" + Filename);

Now you will get the url to your image that can be displayed directly.

将图像文件夹( ...\\Shopy\\Images )链接到应用程序下的虚拟文件夹,以便可以在<img>元素中链接到它们。

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