示例#1
0
        public static void SaveScreenshot(DIBitmap buffer, ScreenshotConfig config)
        {
            Bitmap bitmap = null;

            try
            {
                bitmap = new Bitmap(buffer.Width, buffer.Height, PixelFormat.Format32bppArgb);
                var rect = new Rectangle(Point.Empty, bitmap.Size);

                BitmapData bmpData = null;
                try
                {
                    bmpData = bitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                    NativeMethods.CopyMemory(bmpData.Scan0, buffer.Bits, buffer.BitsCount);
                }
                finally
                {
                    if (bmpData != null)
                    {
                        bitmap.UnlockBits(bmpData);
                    }
                }

                if (config.AutoClipping)
                {
                    bitmap = AutoClipping(bitmap);
                }
            }
            catch (Exception ex)
            {
                bitmap?.Dispose();
                PluginMain.Logger.Log(LogLevel.Error, "OverlayPlugin Can't Take Screenshot: {0}", ex.ToString());
                return;
            }

            using (bitmap)
                using (var src = new Bitmap(bitmap.Width + config.Margin * 2, bitmap.Height + config.Margin * 2, PixelFormat.Format32bppArgb))
                {
                    if (!string.IsNullOrWhiteSpace(config.BackgroundImagePath) && File.Exists(config.BackgroundImagePath))
                    {
                        try
                        {
                            DrawBackground(src, config.BackgroundImagePath, config.BackgroundMode);
                        }
                        catch (Exception ex)
                        {
                            PluginMain.Logger.Log(LogLevel.Error, "OverlayPlugin Can't Take Screenshot: {0}", ex.ToString());
                        }
                    }

                    using (var g = Graphics.FromImage(src))
                    {
                        g.CompositingMode = CompositingMode.SourceOver;
                        g.DrawImageUnscaled(bitmap, config.Margin, config.Margin);
                    }

                    Directory.CreateDirectory(config.SavePath);

                    src.Save(
                        Path.Combine(config.SavePath, DateTime.Now.ToString("'Screenshot_'yyyy-MM-dd_HH-mm-ss.fff'.png'")),
                        ImageFormat.Png);
                }
        }
示例#2
0
 public void SetSurfaceData(IntPtr srcSurfaceData, uint count)
 {
     NativeMethods.CopyMemory(this.Bits, srcSurfaceData, count);
 }