Bitmapsource To Bitmap -----WPF

 /// <summary>
        //Bitmapsource To Bitmap
        /// </summary>
        /// <param name="bs">需转化的Bitmapsource</param>
        /// <returns>Bitmap</returns>
        public static Bitmap BitmapsourceToBitmap(BitmapSource bs) 
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bs.PixelWidth, bs.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            System.Drawing.Imaging.BitmapData data = bmp.LockBits(
                    new System.Drawing.Rectangle(System.Drawing.Point.Empty, bmp.Size), 
                    System.Drawing.Imaging.ImageLockMode.WriteOnly, 
                    System.Drawing.Imaging.PixelFormat.Format32bppPArgb
                    );
            bs.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride); bmp.UnlockBits(data);
            return bmp;
        }

 

posted @ 2022-07-28 15:41  驼七  阅读(29)  评论(0)    收藏  举报