简体   繁体   中英

get Image object from path name

给定路径和文件名,我如何获取Image对象:

Image image = ...(filename)

Another alternative is to use a Bitmap object (which inherits from Image) like so:

Bitmap bitmap = new Bitmap(imagePath);

(This works for all image formats, not just *.bmp as the name might imply.)

// 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#.

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.

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