Szerkesztés

Megosztás a következőn keresztül:


Icon.ToBitmap Method

Definition

Converts this Icon to a GDI+ Bitmap.

public:
 System::Drawing::Bitmap ^ ToBitmap();
public System.Drawing.Bitmap ToBitmap ();
member this.ToBitmap : unit -> System.Drawing.Bitmap
Public Function ToBitmap () As Bitmap

Returns

A Bitmap that represents the converted Icon.

Examples

The following code example demonstrates how to use the ToBitmap method. This example is designed to be used with Windows Forms. Create a form and paste the following code into it. Call the IconToBitmap method in the form's .Paint event handler, passing e as PaintEventArgs .

private:
   void IconToBitmap( PaintEventArgs^ e )
   {
      // Construct an Icon.
      System::Drawing::Icon^ icon1 = gcnew System::Drawing::Icon( SystemIcons::Exclamation,40,40 );

      // Call ToBitmap to convert it.
      Bitmap^ bmp = icon1->ToBitmap();

      // Draw the bitmap.
      e->Graphics->DrawImage( bmp, Point(30,30) );
   }
private void IconToBitmap(PaintEventArgs e)
{
    // Construct an Icon.
    Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40);

    // Call ToBitmap to convert it.
    Bitmap bmp = icon1.ToBitmap();

    // Draw the bitmap.
    e.Graphics.DrawImage(bmp, new Point(30, 30));
}
Private Sub IconToBitmap(ByVal e As PaintEventArgs)

    ' Construct an Icon.
    Dim icon1 As New Icon(SystemIcons.Exclamation, 40, 40)

    ' Call ToBitmap to convert it.
    Dim bmp As Bitmap = icon1.ToBitmap()

    ' Draw the bitmap.
    e.Graphics.DrawImage(bmp, New Point(30, 30))
End Sub

Remarks

The transparent areas of the icon are lost when it is converted to a bitmap, and the transparent color of the resulting bitmap is set to RGB(13,11,12). The returned bitmap has the same height and width as the original icon.

Applies to