Graphics.FromImage メソッド
指定した Image の新しい Graphics を作成します。
名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
Dim image As Image Dim returnValue As Graphics returnValue = Graphics.FromImage(image)


イメージがインデックス付きのピクセル形式の場合、このメソッドは "インデックス付きのピクセル形式をもつイメージから Graphics オブジェクトを作成することはできません。" というメッセージと共に例外をスローします。インデックス付きのピクセル形式の一覧を次に示します。
-
Format1bppIndexed
-
Format4bppIndexed
-
Format8bppIndexed
このメソッドは、イメージが次のピクセル形式の場合にも例外をスローします。
-
DontCare
-
Format16bppArgb1555
-
Format16bppGrayScale
Graphics メソッドによって作成された Dispose および関連リソースを解放するには、必ず FromImage メソッドを呼び出す必要があります。

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードでは次のアクションを実行します。
-
サンプル用のフォルダにあるグラフィックス ファイル SampImag.jpg から Image を作成します。
Public Sub FromImageImage2(ByVal e As PaintEventArgs) ' Create image. Dim imageFile As Image = Image.FromFile("SampImag.jpg") ' Create graphics object for alteration. Dim newGraphics As Graphics = Graphics.FromImage(imageFile) ' Alter image. newGraphics.FillRectangle(New SolidBrush(Color.Black), _ 100, 50, 100, 100) ' Draw image to screen. e.Graphics.DrawImage(imageFile, New PointF(0.0F, 0.0F)) ' Dispose of graphics object. newGraphics.Dispose() End Sub
public void FromImageImage(PaintEventArgs e) { // Create image. Image imageFile = Image.FromFile("SampImag.jpg"); // Create graphics object for alteration. Graphics newGraphics = Graphics.FromImage(imageFile); // Alter image. newGraphics.FillRectangle(new SolidBrush(Color.Black), 100, 50, 100, 100); // Draw image to screen. e.Graphics.DrawImage(imageFile, new PointF(0.0F, 0.0F)); // Dispose of graphics object. newGraphics.Dispose(); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からGraphics.FromImage メソッドを検索する場合は、下記のリンクをクリックしてください。

- Graphics.FromImage メソッドのページへのリンク