Sdílet prostřednictvím


Bitmap Konstruktory

Definice

Inicializuje novou instanci Bitmap třídy.

Přetížení

Name Description
Bitmap(Image)

Inicializuje novou instanci Bitmap třídy ze zadané existující image.

Bitmap(Stream)

Inicializuje novou instanci Bitmap třídy ze zadaného datového proudu.

Bitmap(String)

Inicializuje novou instanci Bitmap třídy ze zadaného souboru.

Bitmap(Image, Size)

Inicializuje novou instanci Bitmap třídy ze zadané existující image škálované na zadanou velikost.

Bitmap(Int32, Int32)

Inicializuje novou instanci Bitmap třídy se zadanou velikostí.

Bitmap(Stream, Boolean)

Inicializuje novou instanci Bitmap třídy ze zadaného datového proudu.

Bitmap(String, Boolean)

Inicializuje novou instanci Bitmap třídy ze zadaného souboru.

Bitmap(Type, String)

Inicializuje novou instanci Bitmap třídy ze zadaného prostředku.

Bitmap(Image, Int32, Int32)

Inicializuje novou instanci Bitmap třídy ze zadané existující image škálované na zadanou velikost.

Bitmap(Int32, Int32, Graphics)

Inicializuje novou instanci Bitmap třídy se zadanou velikostí a rozlišení zadaného Graphics objektu.

Bitmap(Int32, Int32, PixelFormat)

Inicializuje novou instanci Bitmap třídy se zadanou velikostí a formátem.

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

Inicializuje novou instanci Bitmap třídy se zadanou velikostí, formátem pixelů a daty pixelů.

Bitmap(Image)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadané existující image.

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)

Parametry

original
Image

Ze Image kterého chcete vytvořit nový Bitmap.

Platí pro

Bitmap(Stream)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadaného datového proudu.

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)

Parametry

stream
Stream

Datový proud použitý k načtení image.

Výjimky

stream neobsahuje data obrázku nebo je null.

nebo

stream obsahuje soubor obrázku PNG s jednou dimenzí větší než 65 535 pixelů.

Příklady

Následující příklad kódu ukazuje, jak načíst bitmapu ze streamu.

Tento příklad je navržený tak, aby se používal s Windows Forms. Vytvořte formulář, který obsahuje pojmenovaný PictureBoxPictureBox1. Vložte kód do formuláře a volejte metodu InitializeStreamBitmap z konstruktoru formuláře nebo Load metody zpracování událostí.

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

Poznámky

Musíte zachovat datový proud otevřený po celou dobu života Bitmap.

Kvůli omezení dekodéru GDI+ se vyvolá, System.ArgumentException pokud vytvoříte rastrový obrázek ze souboru .png obrázku s jednou dimenzí větší než 65 535 pixelů.

Viz také

Platí pro

Bitmap(String)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadaného souboru.

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

Parametry

filename
String

Název a cesta rastrového souboru.

Výjimky

Zadaný soubor nebyl nalezen.

Poznámky

Název souboru a cesta mohou být relativní vzhledem k aplikaci nebo absolutní cestě. Pomocí tohoto konstruktoru můžete otevírat obrázky s následujícími formáty souborů: BMP, GIF, EXIF, JPG, PNG a TIFF. Další informace o podporovaných formátech naleznete v tématu Typy rastrových obrázků. Soubor zůstane uzamčený, dokud nebude Bitmap odstraněn.

Viz také

Platí pro

Bitmap(Image, Size)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadané existující image škálované na zadanou velikost.

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)

Parametry

original
Image

Ze Image kterého chcete vytvořit nový Bitmap.

newSize
Size

Struktura Size , která představuje velikost nového Bitmap.

Výjimky

Operace se nezdařila.

Platí pro

Bitmap(Int32, Int32)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy se zadanou velikostí.

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)

Parametry

width
Int32

Šířka v pixelech nového Bitmap.

height
Int32

Výška v pixelech nového Bitmap.

Výjimky

Operace se nezdařila.

Poznámky

Tento konstruktor vytvoří Bitmap hodnotu PixelFormat výčtu .Format32bppArgb

Platí pro

Bitmap(Stream, Boolean)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadaného datového proudu.

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)

Parametry

stream
Stream

Datový proud použitý k načtení image.

useIcm
Boolean

true k použití opravy barev pro toto Bitmap; jinak , false.

Výjimky

stream neobsahuje data obrázku nebo je null.

nebo

stream obsahuje soubor obrázku PNG s jednou dimenzí větší než 65 535 pixelů.

Poznámky

Musíte zachovat datový proud otevřený po celou dobu života Bitmap.

Kvůli omezení dekodéru GDI+ se vyvolá, System.ArgumentException pokud vytvoříte rastrový obrázek ze souboru .png obrázku s jednou dimenzí větší než 65 535 pixelů.

Viz také

Platí pro

Bitmap(String, Boolean)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadaného souboru.

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)

Parametry

filename
String

Název rastrového souboru.

useIcm
Boolean

true k použití opravy barev pro toto Bitmap; jinak , false.

Příklady

Následující příklad kódu ukazuje, jak vytvořit nový rastrový obrázek ze souboru. V příkladu se k GetPixel přebarvení obrázku používají metody a SetPixel metody. Používá také PixelFormat vlastnost.

Tento příklad je navržen tak, aby se používal s formulářem Windows, který obsahuje a pojmenovaný LabelLabel1PictureBox1PictureBoxButton , a Button1v uvedeném pořadí. Vložte kód do formuláře a přidružte Button1_Click metodu k události tlačítka 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

Poznámky

Pomocí tohoto konstruktoru můžete otevírat obrázky s následujícími formáty souborů: BMP, GIF, EXIF, JPG, PNG a TIFF. Další informace o podporovaných formátech naleznete v tématu Typy rastrových obrázků. Soubor zůstane uzamčený, dokud nebude Bitmap odstraněn.

Viz také

Platí pro

Bitmap(Type, String)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadaného prostředku.

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)

Parametry

type
Type

Třída použitá k extrakci prostředku.

resource
String

Název zdroje.

Příklady

Následující příklad kódu ukazuje, jak vytvořit bitmapu z typu a jak použít metodu Save . Pokud chcete tento příklad spustit, vložte kód do formuláře Windows. Zpracování události formuláře Paint a volání ConstructFromResourceSaveAsGif metody a předání e jako 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

Poznámky

Tento konstruktor kombinuje obor názvů daného typu s názvem řetězce prostředku a hledá shodu v manifestu sestavení. Můžete například předat Button typ a Button.bmp tento konstruktor a bude hledat prostředek s názvem System.Windows.Forms.Button.bmp.

Viz také

Platí pro

Bitmap(Image, Int32, Int32)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy ze zadané existující image škálované na zadanou velikost.

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)

Parametry

original
Image

Ze Image kterého chcete vytvořit nový Bitmap.

width
Int32

Šířka v pixelech nového Bitmap.

height
Int32

Výška v pixelech nového Bitmap.

Výjimky

Operace se nezdařila.

Platí pro

Bitmap(Int32, Int32, Graphics)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy se zadanou velikostí a rozlišení zadaného Graphics objektu.

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)

Parametry

width
Int32

Šířka v pixelech nového Bitmap.

height
Int32

Výška v pixelech nového Bitmap.

g
Graphics

Objekt Graphics , který určuje rozlišení pro nový Bitmap.

Výjimky

Poznámky

Nová Bitmap , kterou tato metoda vytvoří, přebírá své horizontální a vertikální rozlišení z DpiX a DpiY vlastnosti g, v uvedeném pořadí.

Platí pro

Bitmap(Int32, Int32, PixelFormat)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy se zadanou velikostí a formátem.

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)

Parametry

width
Int32

Šířka v pixelech nového Bitmap.

height
Int32

Výška v pixelech nového Bitmap.

format
PixelFormat

Formát pixelu pro nový Bitmap. To musí zadat hodnotu, která začíná Formatna .

Výjimky

Je PixelFormat zadána hodnota, jejíž název nezačíná formátem. Například zadání Gdi způsobí ArgumentException, ale Format48bppRgb nebude.

Platí pro

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

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Inicializuje novou instanci Bitmap třídy se zadanou velikostí, formátem pixelů a daty pixelů.

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)

Parametry

width
Int32

Šířka v pixelech nového Bitmap.

height
Int32

Výška v pixelech nového Bitmap.

stride
Int32

Celé číslo, které určuje posun bajtů mezi začátkem jednoho řádku skenování a dalším. To je obvykle (ale ne nutně) počet bajtů ve formátu pixelů (například 2 pro 16 bitů na pixel) vynásobený šířkou rastrového obrázku. Hodnota předaná tomuto parametru musí být násobkem čtyř.

format
PixelFormat

Formát pixelu pro nový Bitmap. To musí zadat hodnotu, která začíná Formatna .

scan0
IntPtr

nativeint

Ukazatel na pole bajtů, které obsahuje data v pixelech.

Výjimky

Je PixelFormat zadána hodnota, jejíž název nezačíná formátem. Například zadání Gdi způsobí ArgumentException, ale Format48bppRgb nebude.

Příklady

Následující příklad kódu ukazuje, jak použít Bitmap(Int32, Int32, Int32, PixelFormat, IntPtr) konstruktor. Tento příklad je navržený tak, aby se používal s Windows Forms a vyžaduje PaintEventArgs parametr, což je parametr Paint události.

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

Poznámky

Volající zodpovídá za přidělování a uvolnění bloku paměti určeného parametrem scan0 . Paměť by však neměla být vydána, dokud nebude vydána související Bitmap .

Platí pro