從指定的檔案建立 Image 物件。
命名空間: System.Drawing
public static Image FromFile(
string filename
)
參數
- filename
-
類型:System.String
字串,包含從其中建立 Image 之檔案的名稱。
傳回值
private void DemonstratePropertyItem(PaintEventArgs e)
{
// Create two images.
Image image1 = Image.FromFile("c:\\FakePhoto1.jpg");
Image image2 = Image.FromFile("c:\\FakePhoto2.jpg");
// Get a PropertyItem from image1.
PropertyItem propItem = image1.GetPropertyItem(20624);
// Change the ID of the PropertyItem.
propItem.Id = 20625;
// Set the PropertyItem for image2.
image2.SetPropertyItem(propItem);
// Draw the image.
e.Graphics.DrawImage(image2, 20.0F, 20.0F);
}
System.Drawing.Image.FromFile(filename)的使用方法就是将图片文件的路径作为参数传进去,得到一个解码后的Image对象。
public static System.Drawing.Image FromFile(string filename)
具体用法:
从指定的文件创建 System.Drawing.Image。参数:filename: 字符串,包含要从中创建 System.Drawing.Image 的文件的名称。 返回值:此方法创建的 System.Drawing.Image。
下一篇:Graphics 类
相关新闻
- 小程序登录流程图理解 2020-08-18
- 在C#中获取web.config中的配置信息 2021-08-23
- 小程序open-data头像样式 2021-04-10
- 小程序rich-text 富文本解析图片过大和图片路径的问题 2020-11-25
- C#中去掉字符串的最后一个字符 2020-11-23