次の方法で共有


Bitmap コンストラクター

定義

Bitmap クラスの新しいインスタンスを初期化します。

オーバーロード

名前 説明
Bitmap(Image)

指定した既存のイメージから Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Stream)

指定したデータ ストリームから Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(String)

指定したファイルから Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Image, Size)

指定した既存のイメージから Bitmap クラスの新しいインスタンスを初期化し、指定したサイズにスケーリングします。

Bitmap(Int32, Int32)

指定したサイズで Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Stream, Boolean)

指定したデータ ストリームから Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(String, Boolean)

指定したファイルから Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Type, String)

指定したリソースから Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Image, Int32, Int32)

指定した既存のイメージから Bitmap クラスの新しいインスタンスを初期化し、指定したサイズにスケーリングします。

Bitmap(Int32, Int32, Graphics)

指定したサイズと、指定したGraphics オブジェクトの解像度を使用して、Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Int32, Int32, PixelFormat)

指定したサイズと形式を使用して、 Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr)

指定したサイズ、ピクセル形式、およびピクセル データを使用して、 Bitmap クラスの新しいインスタンスを初期化します。

Bitmap(Image)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定した既存のイメージから Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(System::Drawing::Image ^ original);
public Bitmap(System.Drawing.Image original);
new System.Drawing.Bitmap : System.Drawing.Image -> System.Drawing.Bitmap
Public Sub New (original As Image)

パラメーター

original
Image

新しいBitmapの作成元となるImage

適用対象

Bitmap(Stream)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したデータ ストリームから Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(System::IO::Stream ^ stream);
public Bitmap(System.IO.Stream stream);
new System.Drawing.Bitmap : System.IO.Stream -> System.Drawing.Bitmap
Public Sub New (stream As Stream)

パラメーター

stream
Stream

イメージの読み込みに使用されるデータ ストリーム。

例外

stream には画像データが含まれていないか、 null

-又は-

stream には、1 次元が 65,535 ピクセルを超える PNG イメージ ファイルが含まれています。

次のコード例は、ストリームからビットマップを読み込む方法を示しています。

この例は、Windows フォームで使用するように設計されています。 PictureBox1という名前のPictureBoxを含むフォームを作成します。 コードをフォームに貼り付け、フォームのコンストラクターまたはイベント処理メソッドから InitializeStreamBitmap メソッド Load 呼び出します。

void InitializeStreamBitmap()
{
   try
   {
      System::Net::WebRequest^ request = System::Net::WebRequest::Create( "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif" );
      System::Net::WebResponse^ response = request->GetResponse();
      System::IO::Stream^ responseStream = response->GetResponseStream();
      Bitmap^ bitmap2 = gcnew Bitmap( responseStream );
      PictureBox1->Image = bitmap2;
   }
   catch ( System::Net::WebException^ ) 
   {
      MessageBox::Show( "There was an error opening the image file."
      "Check the URL" );
   }

}
private void InitializeStreamBitmap()
{
    try
    {
        System.Net.WebRequest request = 
            System.Net.WebRequest.Create(
            "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif");
        System.Net.WebResponse response = request.GetResponse();
        System.IO.Stream responseStream = 
            response.GetResponseStream();
        Bitmap bitmap2 = new Bitmap(responseStream);
        PictureBox1.Image = bitmap2;
    }
    catch(System.Net.WebException)
    {
        MessageBox.Show("There was an error opening the image file."
           + "Check the URL");
    }
}
Private Sub InitializeStreamBitmap()
    Try
        Dim request As System.Net.WebRequest = _
            System.Net.WebRequest.Create( _
            "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif")
        Dim response As System.Net.WebResponse = request.GetResponse()
        Dim responseStream As System.IO.Stream = response.GetResponseStream()
        Dim bitmap2 As New Bitmap(responseStream)
        PictureBox1.Image = bitmap2

    Catch ex As System.Net.WebException
        MessageBox.Show("There was an error opening the image file. Check the URL")
    End Try
End Sub

注釈

Bitmapの有効期間中、ストリームを開いたままにする必要があります。

GDI+ デコーダーの制限により、1 次元が 65,535 ピクセルを超える .png イメージ ファイルからビットマップを構築すると、 System.ArgumentException がスローされます。

こちらもご覧ください

適用対象

Bitmap(String)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したファイルから Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(System::String ^ filename);
public Bitmap(string filename);
new System.Drawing.Bitmap : string -> System.Drawing.Bitmap
Public Sub New (filename As String)

パラメーター

filename
String

ビットマップ ファイルの名前とパス。

例外

指定されたファイルが見つかりません。

注釈

ファイル名とパスは、アプリケーションまたは絶対パスに対する相対パスにすることができます。 このコンストラクターを使用して、BMP、GIF、EXIF、JPG、PNG、TIFF のファイル形式で画像を開きます。 サポートされている形式の詳細については、「 ビットマップの種類」を参照してください。 ファイルは、 Bitmap が破棄されるまでロックされたままになります。

こちらもご覧ください

適用対象

Bitmap(Image, Size)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定した既存のイメージから Bitmap クラスの新しいインスタンスを初期化し、指定したサイズにスケーリングします。

public:
 Bitmap(System::Drawing::Image ^ original, System::Drawing::Size newSize);
public Bitmap(System.Drawing.Image original, System.Drawing.Size newSize);
new System.Drawing.Bitmap : System.Drawing.Image * System.Drawing.Size -> System.Drawing.Bitmap
Public Sub New (original As Image, newSize As Size)

パラメーター

original
Image

新しいBitmapの作成元となるImage

newSize
Size

新しいBitmapのサイズを表すSize構造体。

例外

処理に失敗しました。

適用対象

Bitmap(Int32, Int32)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したサイズで Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(int width, int height);
public Bitmap(int width, int height);
new System.Drawing.Bitmap : int * int -> System.Drawing.Bitmap
Public Sub New (width As Integer, height As Integer)

パラメーター

width
Int32

新しい Bitmapの幅 (ピクセル単位)。

height
Int32

新しい Bitmapの高さ (ピクセル単位)。

例外

処理に失敗しました。

注釈

このコンストラクターは、Format32bppArgbPixelFormat列挙値を持つBitmapを作成します。

適用対象

Bitmap(Stream, Boolean)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したデータ ストリームから Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(System::IO::Stream ^ stream, bool useIcm);
public Bitmap(System.IO.Stream stream, bool useIcm);
new System.Drawing.Bitmap : System.IO.Stream * bool -> System.Drawing.Bitmap
Public Sub New (stream As Stream, useIcm As Boolean)

パラメーター

stream
Stream

イメージの読み込みに使用されるデータ ストリーム。

useIcm
Boolean

この に色補正を使用する場合は &。それ以外の場合は

例外

stream には画像データが含まれていないか、 null

-又は-

stream には、1 次元が 65,535 ピクセルを超える PNG イメージ ファイルが含まれています。

注釈

Bitmapの有効期間中、ストリームを開いたままにする必要があります。

GDI+ デコーダーの制限により、1 次元が 65,535 ピクセルを超える .png イメージ ファイルからビットマップを構築すると、 System.ArgumentException がスローされます。

こちらもご覧ください

適用対象

Bitmap(String, Boolean)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したファイルから Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(System::String ^ filename, bool useIcm);
public Bitmap(string filename, bool useIcm);
new System.Drawing.Bitmap : string * bool -> System.Drawing.Bitmap
Public Sub New (filename As String, useIcm As Boolean)

パラメーター

filename
String

ビットマップ ファイルの名前。

useIcm
Boolean

この に色補正を使用する場合は &。それ以外の場合は

次のコード例は、ファイルから新しいビットマップを構築する方法を示しています。 この例では、 GetPixel メソッドと SetPixel メソッドを使用してイメージの色を変更します。 また、 PixelFormat プロパティも使用します。

この例は、Label1PictureBox1Button1という名前のLabelPictureBoxButtonをそれぞれ含む Windows フォームで使用するように設計されています。 コードをフォームに貼り付け、 Button1_Click メソッドをボタンの Click イベントに関連付けます。

private:
   Bitmap^ image1;
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      try
      {
         
         // Retrieve the image.
         image1 = gcnew Bitmap( "C:\\Documents and Settings\\All Users\\"
         "Documents\\My Music\\music.bmp",true );
         int x;
         int y;
         
         // Loop through the images pixels to reset color.
         for ( x = 0; x < image1->Width; x++ )
         {
            for ( y = 0; y < image1->Height; y++ )
            {
               Color pixelColor = image1->GetPixel( x, y );
               Color newColor = Color::FromArgb( pixelColor.R, 0, 0 );
               image1->SetPixel( x, y, newColor );

            }

         }
         
         // Set the PictureBox to display the image.
         PictureBox1->Image = image1;
         
         // Display the pixel format in Label1.
         Label1->Text = String::Format( "Pixel format: {0}", image1->PixelFormat );
      }
      catch ( ArgumentException^ ) 
      {
         MessageBox::Show( "There was an error."
         "Check the path to the image file." );
      }

   }
Bitmap image1;

private void Button1_Click(System.Object sender, System.EventArgs e)
{

    try
    {
        // Retrieve the image.
        image1 = new Bitmap(@"C:\Documents and Settings\All Users\" 
            + @"Documents\My Music\music.bmp", true);

        int x, y;

        // Loop through the images pixels to reset color.
        for(x=0; x<image1.Width; x++)
        {
            for(y=0; y<image1.Height; y++)
            {
                Color pixelColor = image1.GetPixel(x, y);
                Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
                image1.SetPixel(x, y, newColor);
            }
        }

        // Set the PictureBox to display the image.
        PictureBox1.Image = image1;

        // Display the pixel format in Label1.
        Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
    }
    catch(ArgumentException)
    {
        MessageBox.Show("There was an error." +
            "Check the path to the image file.");
    }
}
Dim image1 As Bitmap

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    Try
        ' Retrieve the image.
        image1 = New Bitmap( _
            "C:\Documents and Settings\All Users\Documents\My Music\music.bmp", _
            True)

        Dim x, y As Integer

        ' Loop through the images pixels to reset color.
        For x = 0 To image1.Width - 1
            For y = 0 To image1.Height - 1
                Dim pixelColor As Color = image1.GetPixel(x, y)
                Dim newColor As Color = _
                    Color.FromArgb(pixelColor.R, 0, 0)
                image1.SetPixel(x, y, newColor)
            Next
        Next

        ' Set the PictureBox to display the image.
        PictureBox1.Image = image1

        ' Display the pixel format in Label1.
        Label1.Text = "Pixel format: " + image1.PixelFormat.ToString()

    Catch ex As ArgumentException
        MessageBox.Show("There was an error." _
            & "Check the path to the image file.")
    End Try
End Sub

注釈

このコンストラクターを使用して、BMP、GIF、EXIF、JPG、PNG、TIFF のファイル形式で画像を開きます。 サポートされている形式の詳細については、「 ビットマップの種類」を参照してください。 ファイルは、 Bitmap が破棄されるまでロックされたままになります。

こちらもご覧ください

適用対象

Bitmap(Type, String)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したリソースから Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(Type ^ type, System::String ^ resource);
public Bitmap(Type type, string resource);
new System.Drawing.Bitmap : Type * string -> System.Drawing.Bitmap
Public Sub New (type As Type, resource As String)

パラメーター

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 = 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(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 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

注釈

このコンストラクターは、指定された型の名前空間とリソースの文字列名を組み合わせ、アセンブリ マニフェストで一致するものを探します。 たとえば、このコンストラクターに Button 型と Button.bmp を渡すと、 System.Windows.Forms.Button.bmpという名前のリソースが検索されます。

こちらもご覧ください

適用対象

Bitmap(Image, Int32, Int32)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定した既存のイメージから Bitmap クラスの新しいインスタンスを初期化し、指定したサイズにスケーリングします。

public:
 Bitmap(System::Drawing::Image ^ original, int width, int height);
public Bitmap(System.Drawing.Image original, int width, int height);
new System.Drawing.Bitmap : System.Drawing.Image * int * int -> System.Drawing.Bitmap
Public Sub New (original As Image, width As Integer, height As Integer)

パラメーター

original
Image

新しいBitmapの作成元となるImage

width
Int32

新しい Bitmapの幅 (ピクセル単位)。

height
Int32

新しい Bitmapの高さ (ピクセル単位)。

例外

処理に失敗しました。

適用対象

Bitmap(Int32, Int32, Graphics)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したサイズと、指定したGraphics オブジェクトの解像度を使用して、Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(int width, int height, System::Drawing::Graphics ^ g);
public Bitmap(int width, int height, System.Drawing.Graphics g);
new System.Drawing.Bitmap : int * int * System.Drawing.Graphics -> System.Drawing.Bitmap
Public Sub New (width As Integer, height As Integer, g As Graphics)

パラメーター

width
Int32

新しい Bitmapの幅 (ピクセル単位)。

height
Int32

新しい Bitmapの高さ (ピクセル単位)。

g
Graphics

新しいBitmapの解像度を指定するGraphics オブジェクト。

例外

gnullです。

注釈

このメソッドが作成する新しいBitmapは、gDpiXプロパティとDpiYプロパティから水平方向と垂直方向の解像度をそれぞれ受け取ります。

適用対象

Bitmap(Int32, Int32, PixelFormat)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したサイズと形式を使用して、 Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(int width, int height, System::Drawing::Imaging::PixelFormat format);
public Bitmap(int width, int height, System.Drawing.Imaging.PixelFormat format);
new System.Drawing.Bitmap : int * int * System.Drawing.Imaging.PixelFormat -> System.Drawing.Bitmap
Public Sub New (width As Integer, height As Integer, format As PixelFormat)

パラメーター

width
Int32

新しい Bitmapの幅 (ピクセル単位)。

height
Int32

新しい Bitmapの高さ (ピクセル単位)。

format
PixelFormat

新しい Bitmapのピクセル形式。 これは、 Formatで始まる値を指定する必要があります。

例外

名前が Format で始まらないPixelFormat値を指定します。 たとえば、 Gdi を指定すると ArgumentExceptionが発生しますが、 Format48bppRgb は発生しません。

適用対象

Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定したサイズ、ピクセル形式、およびピクセル データを使用して、 Bitmap クラスの新しいインスタンスを初期化します。

public:
 Bitmap(int width, int height, int stride, System::Drawing::Imaging::PixelFormat format, IntPtr scan0);
public Bitmap(int width, int height, int stride, System.Drawing.Imaging.PixelFormat format, IntPtr scan0);
new System.Drawing.Bitmap : int * int * int * System.Drawing.Imaging.PixelFormat * nativeint -> System.Drawing.Bitmap
Public Sub New (width As Integer, height As Integer, stride As Integer, format As PixelFormat, scan0 As IntPtr)

パラメーター

width
Int32

新しい Bitmapの幅 (ピクセル単位)。

height
Int32

新しい Bitmapの高さ (ピクセル単位)。

stride
Int32

1 つのスキャン行の先頭と次のスキャン行の間のバイト オフセットを指定する整数。 通常、これはピクセル形式のバイト数 (たとえば、1 ピクセルあたり 16 ビットの場合は 2) にビットマップの幅を乗算したものです (ただし、必ずしもそうではありません)。 このパラメーターに渡される値は、4 の倍数である必要があります。

format
PixelFormat

新しい Bitmapのピクセル形式。 これは、 Formatで始まる値を指定する必要があります。

scan0
IntPtr

nativeint

ピクセル データを含むバイト配列へのポインター。

例外

名前が Format で始まらないPixelFormat値を指定します。 たとえば、 Gdi を指定すると ArgumentExceptionが発生しますが、 Format48bppRgb は発生しません。

次のコード例は、 Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) コンストラクターの使用方法を示しています。 この例は Windows フォームで使用するように設計されており、Paint イベントのパラメーターである PaintEventArgs パラメーターが必要です。

private void BitmapConstructorEx(PaintEventArgs e)
{

    // Create a bitmap.
    Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg");
    
   // Retrieve the bitmap data from the bitmap.
    System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), 
        ImageLockMode.ReadOnly, bmp.PixelFormat);

    //Create a new bitmap.
    Bitmap newBitmap = new Bitmap(200, 200, bmpData.Stride, bmp.PixelFormat, bmpData.Scan0);

    bmp.UnlockBits(bmpData);

    // Draw the new bitmap.
    e.Graphics.DrawImage(newBitmap, 10, 10);
}
Private Sub BitmapConstructorEx(ByVal e As PaintEventArgs)

    ' Create a bitmap.
    Dim bmp As New Bitmap("c:\fakePhoto.jpg")

    ' Retrieve the bitmap data from the bitmap.
    Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), _
        ImageLockMode.ReadOnly, bmp.PixelFormat)

    'Create a new bitmap.
    Dim newBitmap As New Bitmap(200, 200, bmpData.Stride, bmp.PixelFormat, bmpData.Scan0)

    bmp.UnlockBits(bmpData)

    ' Draw the new bitmap.
    e.Graphics.DrawImage(newBitmap, 10, 10)

End Sub

注釈

呼び出し元は、 scan0 パラメーターで指定されたメモリ ブロックの割り当てと解放を担当します。 ただし、関連する Bitmap が解放されるまで、メモリを解放しないでください。

適用対象