Graphics.FromImage メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Graphics.FromImage メソッドの意味・解説 

Graphics.FromImage メソッド

指定した Image の新しい Graphics を作成します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

例外例外
例外の種類条件

ArgumentNullException

image が null 参照 (Visual Basic では Nothing) です。

Exception

image がインデックス付きのピクセル形式であるか、またはその形式が未定義です。

解説解説

イメージがインデックス付きのピクセル形式の場合、このメソッドは "インデックス付きのピクセル形式をもつイメージから Graphics オブジェクトを作成することはできません。" というメッセージと共に例外をスローします。インデックス付きのピクセル形式の一覧を次に示します。

  • Format1bppIndexed

  • Format4bppIndexed

  • Format8bppIndexed

このメソッドは、イメージが次のピクセル形式の場合にも例外をスローします。

  • Undefined

  • DontCare

  • Format16bppArgb1555

  • Format16bppGrayScale

Graphics メソッドによって作成された Dispose および関連リソースを解放するには、必ず FromImage メソッドを呼び出す必要があります。

使用例使用例

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードでは次のアクションを実行します。

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();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Graphics.FromImage メソッド」の関連用語

Graphics.FromImage メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Graphics.FromImage メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS