Bitmap(Type, String) 图片路径

Bitmap(Type, String)

从指定的资源初始化 Bitmap 类的新实例。

public Bitmap (Type type, string resource);

参数

type
Type

用于提取资源的类。

resource
String

资源的名称。

示例

下面的代码示例演示如何从类型构造位图,以及如何使用 Save 方法。 若要运行此示例,请将代码粘贴到 Windows 窗体中。 处理窗体的 Paint 事件并调用 ConstructFromResourceSaveAsGif 方法,并将 e 作为 PaintEventArgs

 
private void ConstructFromResourceSaveAsGif(PaintEventArgs e)
{

    // Construct a bitmap from the button image resource.
    Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");

    // Save the image as a GIF.
    bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);

    // Construct a new image from the GIF file.
    Bitmap bmp2 = new Bitmap("c:\\button.gif");

    // Draw the two images.
    e.Graphics.DrawImage(bmp1, new Point(10, 10));
    e.Graphics.DrawImage(bmp2, new Point(10, 40));

    // Dispose of the image files.
    bmp1.Dispose();
    bmp2.Dispose();
}

注解

此构造函数将给定类型的命名空间与资源的字符串名称组合在一起,并在程序集清单中查找匹配项。 例如,你可以将 Button 类型和 Button.bmp 传递到此构造函数,它将查找名为 System.Windows.Forms.Button.bmp的资源。

猜你喜欢

转载自www.cnblogs.com/jshchg/p/12586589.html