如何在C#中表示任何格式的图像 [英] how do I represent any formats of images in C#

查看:97
本文介绍了如何在C#中表示任何格式的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

极客,



我在服务器中检索特定的文件夹名称。我有不同格式的文件夹名称的图像(.jpg,.jpeg,.png)如何表示它们???



imgbtn.ImageUrl =〜 / Images /+ d.Name +。jpg;



我需要这样的d.Name +。jpg / .jpeg / .png



请有人帮助我

Hi geeks,

I retrieve specific folder names in server. I've images for certain folder names with different formats(.jpg,.jpeg,.png) How to represent them ???

imgbtn.ImageUrl = "~/Images/" + d.Name+".jpg";

I need like this d.Name+".jpg/.jpeg/.png"

Pls someone help me

推荐答案

您可以执行以下操作。

You can do the following.
if (System.IO.File.Exists("~/Images/" + d.Name+".jpg"))
{
     imgbtn.ImageUrl = "~/Images/" + d.Name+".jpg";
}
else if (System.IO.File.Exists("~/Images/" + d.Name + ".jpeg"))
{
     imgbtn.ImageUrl = "~/Images/" + d.Name + ".jpeg";
}
else if (System.IO.File.Exists("~/Images/" + d.Name + ".png"))
{
     imgbtn.ImageUrl = "~/Images/" + d.Name + ".png";
}


ImageUrls必须是特定文件 - 这意味着特定的文件名,包括扩展名。



没有机制可以说这三种可能性中的一种,如果它们存在 - 相反,你必须检查存在的文件( File.Exists [ ^ ]会这样做)找到特定文件,然后使用完整的URL。
ImageUrls must be to a specific file - which means a specific file name, including extension.

There is no mechanism for saying "one of these three possibilities, if any of them exist" - instead you will have to check for the file existance (File.Exists[^] will do it) to locate teh specific file, and then use the full URL for that.


这篇关于如何在C#中表示任何格式的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆