c# Bitmap arka planı transparent(şeffaf) nasıl yapılır?

emkoroglu (327) 9 yıl önce sordu

ilk bitmap 150X112 ikinicisi ise 150x150 ben ilkini ikinic bitmap uzerınde oluşturup geri kalan pixelleri şeffaf olmasını istiyorum. yani height 38 pixel fazla olucak bu fazlalıgışeffaf yapıp web sitesinde goruntulenınce gorunmesını ıstemıyorum. aşagıdakı kodda geri kalan pixel'leri beyaz yapıyor.

Bitmap bImage = new Bitmap(150, 122);
Bitmap bImage_trans = new Bitmap(150, 150);

for (int w = 0; w < bImage .Width; w++)
                {
                    for (int h = 0; h < bImage_trans.Height ; h++)
                    {
                        if (bImage .Height <= h)
                        {
                           bImage_trans .SetPixel(w, h, Color.FromArgb(255, 255, 255));
                        }
                        else
                        {
                            Color color = bImage .GetPixel(w, h);
                            bImage_trans .SetPixel(w, h, color);
                        }
                    }
                }

 

Toplam 2 cevap


emkoroglu (327) 9 yıl önce cevapladı
 using (var gr = Graphics.FromImage(new Bitmap(1024,768)))
                {
                    gr.Clear(Color.Transparent);
                    gr.DrawImage(bImage, new Rectangle(0, 0, istenilen_width, istenilen_height));
                   bos_bitmap.Save("c:/result.png", ImageFormat.Png);
                }

 

cemkara (4215) 9 yıl önce cevapladı

Şöyle bir örnek fikir verebilir diye düşünüyorum

{

    // Resim dosyasından bitmap oluştur.
    Bitmap myBitmap = new Bitmap("Grapes.gif");

    //  myBitmap ekana çiz.
    e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
        myBitmap.Height);

    // Transparan yap
    myBitmap.MakeTransparent();

    // Transparan resmi ekrana çiz.
    e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
        myBitmap.Width, myBitmap.Height);
}

Bu metod 

MakeTransparent();

Bitmap resmi transparan yapar.  Örnek MSDN'den alınmıştır.
 

emkoroglu 9 yıl önce

teşekkürler. problemi çözdüm