Share via


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)

지정된 Bitmap 개체의 해상도와 지정된 크기를 사용하여 Graphics 클래스의 새 인스턴스를 초기화합니다.

Bitmap(Int32, Int32, PixelFormat)

지정된 크기와 형식을 사용하여 Bitmap 클래스의 새 인스턴스를 초기화합니다.

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

지정된 크기, 픽셀 형식 및 픽셀 데이터를 사용하여 Bitmap 클래스의 새 인스턴스를 초기화합니다.

Bitmap(Image)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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

Image을 만들 Bitmap입니다.

적용 대상

Bitmap(Stream)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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에 단일 크기가 65,535픽셀보다 큰 PNG 이미지 파일이 있는 경우

예제

다음 코드 예제에서는 스트림에서 비트맵을 로드하는 방법을 보여 줍니다.

이 예제는 Windows Forms 함께 사용하도록 설계되었습니다. 이름이 PictureBox1인 폼을 PictureBox Create. 코드를 양식에 붙여넣고 폼의 생성자 또는 Load 이벤트 처리 메서드에서 메서드를 호출 InitializeStreamBitmap 합니다.

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+ 디코더 System.ArgumentException 의 제한으로 인해 단일 차원이 65,535픽셀보다 큰 .png 이미지 파일에서 비트맵을 생성하면 이 throw됩니다.

추가 정보

적용 대상

Bitmap(String)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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

Image을 만들 Bitmap입니다.

newSize
Size

Size의 크기를 나타내는 Bitmap 구조체입니다.

예외

작업이 실패했습니다.

적용 대상

Bitmap(Int32, Int32)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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의 높이(픽셀)입니다.

예외

작업이 실패했습니다.

설명

이 생성자는 의 열거형 값을 사용하여 PixelFormatFormat32bppArgb만듭니다Bitmap.

적용 대상

Bitmap(Stream, Boolean)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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

Bitmap의 색 보정을 사용하면 true이고, 그렇지 않으면 false입니다.

예외

stream이 이미지 데이터를 포함하지 않거나 null인 경우

또는

stream에 단일 크기가 65,535픽셀보다 큰 PNG 이미지 파일이 있는 경우

설명

의 수명 Bitmap동안 스트림을 열어 두어야 합니다.

GDI+ 디코더 System.ArgumentException 의 제한으로 인해 단일 차원이 65,535픽셀보다 큰 .png 이미지 파일에서 비트맵을 생성하면 이 throw됩니다.

추가 정보

적용 대상

Bitmap(String, Boolean)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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

Bitmap의 색 보정을 사용하면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 파일에서 새 비트맵을 생성하는 방법을 보여 줍니다. 이 예제에서는 및 SetPixel 메서드를 사용하여 GetPixel 이미지를 다시 칠합니다. 또한 속성을 사용합니다 PixelFormat .

이 예제는 각각 , PictureBoxButton 라는 Label1PictureBox1 를 포함하는 LabelWindows Form과 Button1함께 사용하도록 설계되었습니다. 코드를 양식에 붙여넣고 메서드를 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)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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 Form에 붙여넣습니다. 양식의 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.bmpButton 이 생성자에 전달할 수 있으며 라는 System.Windows.Forms.Button.bmp리소스를 찾습니다.

추가 정보

적용 대상

Bitmap(Image, Int32, Int32)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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

Image을 만들 Bitmap입니다.

width
Int32

Bitmap의 너비(픽셀)입니다.

height
Int32

Bitmap의 높이(픽셀)입니다.

예외

작업이 실패했습니다.

적용 대상

Bitmap(Int32, Int32, Graphics)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

지정된 Bitmap 개체의 해상도와 지정된 크기를 사용하여 Graphics 클래스의 새 인스턴스를 초기화합니다.

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

Graphics의 해상도를 지정하는 Bitmap 개체입니다.

예외

g이(가) null인 경우

설명

이 메서드가 만드는 새 Bitmap 는 각각 의 및 속성에서 DpiX 가로 및 DpiY 세로 해상도를 g사용합니다.

적용 대상

Bitmap(Int32, Int32, PixelFormat)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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값을 지정해야 합니다.

예외

이름이 서식으로 시작하지 않는 경우, PixelFormat 값이 지정됩니다. 예를 들어, Gdi를 지정하면 ArgumentException이 초래되나, Format48bppRgb는 초래되지 않습니다.

적용 대상

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

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
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

한 스캐닝선의 처음부터 다음 스캐닝선까지의 바이트 오프셋을 지정하는 정수입니다. 일반적으로 이 값은 픽셀 형식의 바이트 수(예: 16비트/픽셀의 경우 2)와 비트맵의 너비를 곱한 값입니다. 이 매개 변수에 전달된 값은 4의 배수여야 합니다.

format
PixelFormat

Bitmap의 픽셀 형식입니다. 로 시작하는 Format값을 지정해야 합니다.

scan0
IntPtr

nativeint

픽셀 데이터가 들어 있는 바이트 배열에 대한 포인터입니다.

예외

이름이 서식으로 시작하지 않는 경우, PixelFormat 값이 지정됩니다. 예를 들어, Gdi를 지정하면 ArgumentException이 초래되나, Format48bppRgb는 초래되지 않습니다.

예제

다음 코드 예제를 사용 하는 방법을 보여 줍니다는 Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) 생성자입니다. 이 예제는 Windows Forms 사용할 수 있도록 설계되었으며 이벤트의 매개 변수인 매개 변수가 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 항목이 해제될 때까지 메모리를 해제하면 안 됩니다.

적용 대상