Bitmap コンストラクタとは? わかりやすく解説

Bitmap コンストラクタ (String)

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

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

例外例外
例外種類条件

System.ArgumentException

streamイメージ データ含まれていない、つまり null 参照 (Visual Basic では Nothing) です。

または

stream に、65,535 ピクセルよりも大き1 次元PNG イメージ ファイル含まれています。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Image)


Bitmap コンストラクタ (Stream, Boolean)

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

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

例外例外
例外種類条件

System.ArgumentException

streamイメージ データ含まれていない、つまり null 参照 (Visual Basic では Nothing) です。

または

stream に、65,535 ピクセルよりも大き1 次元PNG イメージ ファイル含まれています。

解説解説

Bitmap有効期間の間は、このストリーム開いておく必要があります

GDI+ デコーダには制約があるので、65,535 ピクセルよりも大き1 次元.png イメージ ファイルからビットマップ作成した場合System.ArgumentExceptionスローさます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Stream)

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

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

例外例外
例外種類条件

System.ArgumentException

streamイメージ データ含まれていない、つまり null 参照 (Visual Basic では Nothing) です。

または

stream に、65,535 ピクセルよりも大き1 次元PNG イメージ ファイル含まれています。

解説解説

Bitmap有効期間の間は、このストリーム開いておく必要があります

GDI+ デコーダには制約があるので、65,535 ピクセルよりも大き1 次元.png イメージ ファイルからビットマップ作成した場合System.ArgumentExceptionスローさます。

使用例使用例

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

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

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
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");
    }
}
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.set_Image(bitmap2);
    }
    catch (System.Net.WebException exp) {
        MessageBox.Show(("There was an error opening the image file." 
            + "Check the URL"));
    }
} //InitializeStreamBitmap
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Int32, Int32, Int32, PixelFormat, IntPtr)

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

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

Public Sub New ( _
    width As Integer, _
    height As Integer, _
    stride As Integer, _
    format As PixelFormat, _
    scan0 As IntPtr _
)
public Bitmap (
    int width,
    int height,
    int stride,
    PixelFormat format,
    IntPtr scan0
)
public:
Bitmap (
    int width, 
    int height, 
    int stride, 
    PixelFormat format, 
    IntPtr scan0
)
public Bitmap (
    int width, 
    int height, 
    int stride, 
    PixelFormat format, 
    IntPtr scan0
)
public function Bitmap (
    width : int, 
    height : int, 
    stride : int, 
    format : PixelFormat, 
    scan0 : IntPtr
)

パラメータ

width

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

height

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

stride

スキャン ラインの間のバイト オフセット数を指定する整数値。これには、通常 (必須ではありません)、ピクセルあたりのバイト数という形式 (16 ビット/ピクセル場合は 2) にビットマップの幅を乗じた値を指定します。このパラメータに渡す値は、4 の倍数である必要があります

format

新しBitmap の PixelFormat 列挙体。

scan0

ピクセル データ格納するバイト配列へのポインタ

解説解説
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Image, Size)


Bitmap コンストラクタ (String, Boolean)

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

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

例外例外
例外種類条件

System.ArgumentException

streamイメージ データ含まれていない、つまり null 参照 (Visual Basic では Nothing) です。

または

stream に、65,535 ピクセルよりも大き1 次元PNG イメージ ファイル含まれています。

解説解説
使用例使用例

GetPixel および SetPixel メソッド使用してイメージの色を変更する方法次のコード例示しますまた、この例では PixelFormat プロパティ使用してます。

この例は、Label1 という名前の LabelPictureBox1 という名前の PictureBox、および Button1 という名前の Button含んだ Windows フォームでの使用意図してデザインされています。コードフォーム貼り付けButton1_Click メソッドボタンClick イベント関連付けます。

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
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.");
    }
}
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." );
      }

   }
private Bitmap image1;

private void button1_Click(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.get_Width(); x++) {
            for (y = 0; y < image1.get_Height(); y++) {
                Color pixelColor = image1.GetPixel(x, y);
                Color newColor = Color.FromArgb(pixelColor.get_R(), 0, 0);

                image1.SetPixel(x, y, newColor);
            }
        }

        // Set the PictureBox to display the image.
        pictureBox1.set_Image(image1);

        // Display the pixel format in label1.
        label1.set_Text("Pixel format: " 
            + image1.get_PixelFormat().ToString());
    }
    catch (ArgumentException exp) {
        MessageBox.Show(("There was an error."  
            + "Check the path to the image file."));
    }
} //button1_Click
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Image, Int32, Int32)

指定したサイズ使用して指定した既存イメージBitmap クラス新しインスタンス初期化します。

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

例外例外
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Int32, Int32, PixelFormat)

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

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

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Type, String)

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

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

解説解説

このコンストラクタは、特定の型の名前空間リソース文字列名と組み合わせてアセンブリ マニフェスト内で一致探します。たとえば、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Int32, Int32)

指定したサイズ使用してBitmap クラス新しインスタンス初期化します。

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

例外例外
解説解説

このコンストラクタは、Format32bppArgb の PixelFormat 列挙体の値を使用して Bitmap作成します

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ (Int32, Int32, Graphics)

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

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

例外例外
例外種類条件

ArgumentNullException

gnull 参照 (Visual Basic では Nothing) です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Bitmap コンストラクタ

Bitmap クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
Bitmap (Image) 指定した既存イメージ使用してBitmap クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Bitmap (Stream) 指定したデータ ストリームBitmap クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Bitmap (String) 指定したファイルBitmap クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Bitmap (Image, Size) 指定したサイズ使用して指定した既存イメージBitmap クラス新しインスタンス初期化します。
Bitmap (Int32, Int32) 指定したサイズ使用してBitmap クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

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 クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

Bitmap (Int32, Int32, Int32, PixelFormat, IntPtr) 指定したサイズピクセル形式、およびピクセル データ使用してBitmap クラス新しインスタンス初期化します。
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「Bitmap コンストラクタ」の関連用語

Bitmap コンストラクタのお隣キーワード
検索ランキング

   

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



Bitmap コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS