指定したリソースで Bitmap クラスの新しいインスタンスを初期化します。
名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
'宣言
Public Sub New ( _
type As Type, _
resource As String _
)
'使用
Dim type As Type
Dim resource As String
Dim instance As New Bitmap(type, resource)
public Bitmap (
Type type,
string resource
)
public:
Bitmap (
Type^ type,
String^ resource
)
public Bitmap (
Type type,
String resource
)
public function Bitmap (
type : Type,
resource : String
)
パラメータ
- type
リソースの抽出に使用するクラス。
- resource
リソースの名前。
解説
このコンストラクタは、特定の型の名前空間をリソースの文字列名と組み合わせて、アセンブリ マニフェスト内で一致を探します。たとえば、Button 型および Button.bmp をこのコンストラクタに渡すと、コンストラクタは System.Windows.Forms.Button.bmp
という名前のリソースを探します。
使用例
ビットマップを型から作成する方法、および Save メソッドを使用する方法を次のコード例に示します。この例を実行するには、コードを Windows フォームに貼り付けます。フォームの Paint イベントを処理し、ConstructFromResourceSaveAsGif
メソッドを呼び出し、e を PaintEventArgs として渡します。
Private Sub ConstructFromResourceSaveAsGif(ByVal e As PaintEventArgs)
' Construct a bitmap from the button image resource.
Dim bmp1 As New Bitmap(GetType(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.
Dim bmp2 As 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()
End Sub
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();
}
private:
void ConstructFromResourceSaveAsGif(PaintEventArgs^ e)
{
// Construct a bitmap from the button image resource.
Bitmap^ bmp1 = gcnew Bitmap(Button::typeid, "Button.bmp");
String^ savePath =
Environment::GetEnvironmentVariable("TEMP") + "\\Button.bmp";
try
{
// Save the image as a GIF.
bmp1->Save(savePath, System::Drawing::Imaging::ImageFormat::Gif);
}
catch (IOException^)
{
// Carry on regardless
}
// Construct a new image from the GIF file.
Bitmap^ bmp2 = nullptr;
if (File::Exists(savePath))
{
bmp2 = gcnew Bitmap(savePath);
}
// Draw the two images.
e->Graphics->DrawImage(bmp1, Point(10, 10));
// If bmp1 did not save to disk, bmp2 may be null
if (bmp2 != nullptr)
{
e->Graphics->DrawImage(bmp2, Point(10, 40));
}
// Dispose of the image files.
delete bmp1;
if (bmp2 != nullptr)
{
delete bmp2;
}
}
private void ConstructFromResourceSaveAsGif(PaintEventArgs e)
{
// Construct a bitmap from the button image resource.
Bitmap bmp1 = new Bitmap(Button.class.ToType(), "Button.bmp");
// Save the image as a GIF.
bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.get_Gif());
// Construct a new image from the GIF file.
Bitmap bmp2 = new Bitmap("c:\\button.gif");
// Draw the two images.
e.get_Graphics().DrawImage(bmp1, new Point(10, 10));
e.get_Graphics().DrawImage(bmp2, new Point(10, 40));
// Dispose of the image files.
bmp1.Dispose();
bmp2.Dispose();
} //ConstructFromResourceSaveAsGif
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
参照
関連項目
Bitmap クラス
Bitmap メンバ
System.Drawing 名前空間