C#: Draw one Bitmap onto Another, with Transparency

前端 未结 3 562
天涯浪人
天涯浪人 2021-02-05 07:13

I have two Bitmaps, named largeBmp and smallBmp. I want to draw smallBmp onto largeBmp, then draw the result onto the screen. SmallBmp\'s white pixels should be transparent. Her

3条回答
  •  花落未央
    2021-02-05 07:36

    Winform copy image on top of another

        private void timerFFTp_Tick(object sender, EventArgs e)
        {
            if (drawBitmap)
            {
                Bitmap bitmap = new Bitmap(_fftControl.Width, _fftControl.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);   
                _fftControl.DrawToBitmap(bitmap, new Rectangle(0, 0, _fftControl.Width, _fftControl.Height));
                if (!fDraw)
                {
                    bitmap.MakeTransparent();
                    Bitmap fftFormBitmap = new Bitmap(_fftForm.BackgroundImage);
                    Graphics g = Graphics.FromImage(fftFormBitmap);
                    g.DrawImage(bitmap, 0, 0);
                    _fftForm.BackgroundImage = fftFormBitmap;
                }
                else
                {
                    fDraw = false;
                    _fftForm.Width = bitmap.Width + 16;
                    _fftForm.Height = bitmap.Height + 48;
                    _fftForm.BackgroundImage = bitmap;
                }
            }
        }
    

提交回复
热议问题