GDI+ を使用して、アプリケーションにファイルとして存在するイメージをレンダリングできます。 これを行うには、Image クラスの新しいオブジェクト (Bitmapなど) を作成し、使用する描画サーフェイスを参照する Graphics オブジェクトを作成し、DrawImage オブジェクトの Graphics メソッドを呼び出します。 イメージは、グラフィックス クラスによって表される描画サーフェイスに描画されます。 イメージ エディターを使用すると、デザイン時にイメージ ファイルを作成および編集し、実行時に GDI+ でレンダリングできます。 詳細については、「アイコン
GDI+ を使用してイメージをレンダリングするには
表示する画像を表すオブジェクトを作成します。 このオブジェクトは、Image や Bitmapなど、Metafileから継承するクラスのメンバーである必要があります。 例を次に示します。
' Uses the System.Environment.GetFolderPath to get the path to the ' current user's MyPictures folder. Dim myBitmap as New Bitmap _ (System.Environment.GetFolderPath _ (System.Environment.SpecialFolder.MyPictures))
// Uses the System.Environment.GetFolderPath to get the path to the // current user's MyPictures folder. Bitmap myBitmap = new Bitmap (System.Environment.GetFolderPath (System.Environment.SpecialFolder.MyPictures));
// Uses the System.Environment.GetFolderPath to get the path to the // current user's MyPictures folder. Bitmap^ myBitmap = gcnew Bitmap (System::Environment::GetFolderPath (System::Environment::SpecialFolder::MyPictures));
使用する図面サーフェスを表す Graphics オブジェクトを作成します。 詳細については、「方法: 描画用のグラフィックス オブジェクトを作成する」を参照してください。
' Creates a Graphics object that represents the drawing surface of ' Button1. Dim g as Graphics = Button1.CreateGraphics
// Creates a Graphics object that represents the drawing surface of // Button1. Graphics g = Button1.CreateGraphics();
// Creates a Graphics object that represents the drawing surface of // Button1. Graphics^ g = button1->CreateGraphics();
グラフィックス オブジェクトの DrawImage を呼び出して、イメージをレンダリングします。 描画するイメージと、描画する座標の両方を指定する必要があります。
g.DrawImage(myBitmap, 1, 1)
g.DrawImage(myBitmap, 1, 1);
g->DrawImage(myBitmap, 1, 1);
こちらも参照ください
- グラフィックス プログラミングのはじめに
- 方法: 描画 用のグラフィックス オブジェクトを作成する
- GDI+ でのペン、直線、および四角形
- 方法: Windows フォーム にテキストを描画する
- Windows フォームでのグラフィックスと描画
- 線または閉じた図形の描画
- アイコン用イメージ エディター
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback