Bitmap.MakeTransparent Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Membuat warna transparan default transparan untuk ini Bitmap.
Overload
MakeTransparent() |
Membuat warna transparan default transparan untuk ini Bitmap. |
MakeTransparent(Color) |
Membuat warna yang ditentukan transparan untuk ini Bitmap. |
MakeTransparent()
- Sumber:
- Bitmap.cs
- Sumber:
- Bitmap.cs
- Sumber:
- Bitmap.cs
Membuat warna transparan default transparan untuk ini Bitmap.
public:
void MakeTransparent();
public void MakeTransparent ();
member this.MakeTransparent : unit -> unit
Public Sub MakeTransparent ()
Pengecualian
Format gambar adalah Bitmap format ikon.
Operasi gagal.
Contoh
Contoh kode berikut dirancang untuk digunakan dengan Formulir Windows, dan memerlukan PaintEventArgse
, yang merupakan parameter penanganan Paint aktivitas. Kode ini membuat warna transparan default sistem transparan untuk myBitmap
, lalu menggambar Bitmap ke layar.
private:
void MakeTransparent_Example1( PaintEventArgs^ e )
{
// Create a Bitmap object from an image file.
Bitmap^ myBitmap = gcnew Bitmap( "Grapes.gif" );
// Draw myBitmap to the screen.
e->Graphics->DrawImage( myBitmap, 0, 0, myBitmap->Width, myBitmap->Height );
// Make the default transparent color transparent for myBitmap.
myBitmap->MakeTransparent();
// Draw the transparent bitmap to the screen.
e->Graphics->DrawImage( myBitmap, myBitmap->Width, 0, myBitmap->Width, myBitmap->Height );
}
private void MakeTransparent_Example1(PaintEventArgs e)
{
// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Grapes.gif");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
myBitmap.Height);
// Make the default transparent color transparent for myBitmap.
myBitmap.MakeTransparent();
// Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
myBitmap.Width, myBitmap.Height);
}
Private Sub MakeTransparent_Example1(ByVal e As PaintEventArgs)
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("Grapes.gif")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
myBitmap.Height)
' Make the default transparent color transparent for myBitmap.
myBitmap.MakeTransparent()
' Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
myBitmap.Height)
End Sub
Keterangan
Palet sistem mendefinisikan satu warna sebagai transparan default, atau alfa, warna. Metode ini membuat warna transparan default transparan untuk ini Bitmap. Jika tidak ada warna transparan yang ditentukan oleh sistem, LightGray adalah warna transparan.
Saat Anda memanggil MakeTransparent, bitmap akan dikonversi ke Format32bppArgb format , karena format ini mendukung saluran alfa.
Berlaku untuk
MakeTransparent(Color)
- Sumber:
- Bitmap.cs
- Sumber:
- Bitmap.cs
- Sumber:
- Bitmap.cs
Membuat warna yang ditentukan transparan untuk ini Bitmap.
public:
void MakeTransparent(System::Drawing::Color transparentColor);
public void MakeTransparent (System.Drawing.Color transparentColor);
member this.MakeTransparent : System.Drawing.Color -> unit
Public Sub MakeTransparent (transparentColor As Color)
Parameter
Pengecualian
Format gambar adalah Bitmap format ikon.
Operasi gagal.
Contoh
Contoh kode berikut dirancang untuk digunakan dengan Formulir Windows, dan memerlukan PaintEventArgse
, yang merupakan parameter penanganan Paint aktivitas. Kode melakukan tindakan berikut:
Mendapatkan warna piksel dalam Bitmap.
Membuat warna itu transparan untuk bitmap.
Menggambar ke Bitmap layar.
private:
void MakeTransparent_Example2( PaintEventArgs^ e )
{
// Create a Bitmap object from an image file.
Bitmap^ myBitmap = gcnew Bitmap( "Grapes.gif" );
// Draw myBitmap to the screen.
e->Graphics->DrawImage( myBitmap, 0, 0, myBitmap->Width, myBitmap->Height );
// Get the color of a background pixel.
Color backColor = myBitmap->GetPixel( 1, 1 );
// Make backColor transparent for myBitmap.
myBitmap->MakeTransparent( backColor );
// Draw the transparent bitmap to the screen.
e->Graphics->DrawImage( myBitmap, myBitmap->Width, 0, myBitmap->Width, myBitmap->Height );
}
private void MakeTransparent_Example2(PaintEventArgs e)
{
// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("Grapes.gif");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(
myBitmap, 0, 0, myBitmap.Width, myBitmap.Height);
// Get the color of a background pixel.
Color backColor = myBitmap.GetPixel(1, 1);
// Make backColor transparent for myBitmap.
myBitmap.MakeTransparent(backColor);
// Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(
myBitmap, myBitmap.Width, 0, myBitmap.Width, myBitmap.Height);
}
Private Sub MakeTransparent_Example2(ByVal e As PaintEventArgs)
' Create a Bitmap object from an image file.
Dim myBitmap As New Bitmap("Grapes.gif")
' Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
myBitmap.Height)
' Get the color of a background pixel.
Dim backColor As Color = myBitmap.GetPixel(1, 1)
' Make backColor transparent for myBitmap.
myBitmap.MakeTransparent(backColor)
' Draw the transparent bitmap to the screen.
e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
myBitmap.Height)
End Sub
Keterangan
Saat Anda memanggil MakeTransparent, bitmap akan dikonversi ke Format32bppArgb format , karena format ini mendukung saluran alfa.
Berlaku untuk
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk