给定路径和文件名,我如何获取Image
对象:
Image image = ...(filename)
您想要在Image
类上调用静态FromFile
方法 。
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.