[英]get Image object from path name
给定路径和文件名,我如何获取Image
对象:
Image image = ...(filename)
您想要在Image
类上调用静态FromFile
方法 。
Another alternative is to use a Bitmap object (which inherits from Image) like so: 另一种方法是使用Bitmap对象(继承自Image),如下所示:
Bitmap bitmap = new Bitmap(imagePath);
(This works for all image formats, not just *.bmp as the name might imply.) (这适用于所有图像格式,而不仅仅是* .bmp,因为名称可能暗示。)
// Get original filename with extention
string filenameWithPath = "C:\pictures\peanutbutterjellytime.jpg;
filename = System.IO.Path.GetFileName(filenameWithPath);
If you're playing with images in memory, I've found that bobpowell.net has a GREAT site for GDI work in C#. 如果你在内存中玩图像,我发现bobpowell.net有一个很棒的网站,用于在C#中进行GDI工作。
No.. I'm not related to, associated with or hired by Bob Powell. 不......我与鲍勃鲍威尔没有关联,关联或雇用。 I just really enjoy his work.
我真的很喜欢他的作品。 =)
=)
Also, if you're having trouble getting the path of the resource (trickiest part) you can do a : 此外,如果您在获取资源路径(最棘手的部分)时遇到问题,您可以执行以下操作:
Assembly myAssembly = Assembly.GetExecutingAssembly();
string[] names = myAssembly.GetManifestResourceNames();
foreach (string name in names)
{
Console.WriteLine( name );
}
Which shows all paths for resources. 其中显示了资源的所有路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.