Пример #1
0
        void renderer_Render(object sender, RenderEventArgs e)
        {
            if (!this.terminated)
            {
                try
                {
                    if (surfaceBuffer != null &&
                        (surfaceBuffer.Width != e.Width || surfaceBuffer.Height != e.Height))
                    {
                        surfaceBuffer.Dispose();
                        surfaceBuffer = null;
                    }

                    if (surfaceBuffer == null)
                    {
                        surfaceBuffer = new DIBitmap(e.Width, e.Height);
                    }

                    // TODO: DirtyRect に対応
                    surfaceBuffer.SetSurfaceData(e.Buffer, (uint)(e.Width * e.Height * 4));

                    UpdateLayeredWindowBitmap();
                }
                catch
                {
                }
            }
        }
Пример #2
0
        void renderer_Render(object sender, RenderEventArgs e)
        {
            if (!this.terminated)
            {
                try
                {
                    if (surfaceBuffer != null &&
                        (surfaceBuffer.Width != e.Width || surfaceBuffer.Height != e.Height))
                    {
                        surfaceBuffer.Dispose();
                        surfaceBuffer = null;
                    }

                    if (surfaceBuffer == null)
                    {
                        //using (var gScreen = Graphics.FromHwnd(Handle))
                        //{
                        //var hScreenDC = gScreen.GetHdc();
                        surfaceBuffer = new DIBitmap(e.Width, e.Height);
                        //gScreen.ReleaseHdc(hScreenDC);
                        //}
                    }

                    // TODO: DirtyRect に対応
                    surfaceBuffer.SetSurfaceData(e.Buffer, (uint)(e.Width * e.Height * 4));

                    UpdateLayeredWindowBitmap();
                }
                catch
                {
                }
            }
        }
Пример #3
0
 private void renderer_Render(object sender, RenderEventArgs e)
 {
     if (this.terminated)
     {
         return;
     }
     try
     {
         if (this.surfaceBuffer != null && (this.surfaceBuffer.Width != e.Width || this.surfaceBuffer.Height != e.Height))
         {
             this.surfaceBuffer.Dispose();
             this.surfaceBuffer = (DIBitmap)null;
         }
         if (this.surfaceBuffer == null)
         {
             this.surfaceBuffer = new DIBitmap(e.Width, e.Height);
         }
         this.surfaceBuffer.SetSurfaceData(e.Buffer, (uint)(e.Width * e.Height * 4));
         this.UpdateLayeredWindowBitmap();
     }
     catch
     {
     }
 }
Пример #4
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);
                }
        }
Пример #5
0
        void renderer_Render(object sender, RenderEventArgs e)
        {
            if (!this.terminated)
            {
                try
                {
                    if (surfaceBuffer != null &&
                        (surfaceBuffer.Width != e.Width || surfaceBuffer.Height != e.Height))
                    {
                        surfaceBuffer.Dispose();
                        surfaceBuffer = null;
                    }

                    if (surfaceBuffer == null)
                    {
                        surfaceBuffer = new DIBitmap(e.Width, e.Height);
                    }

                    // TODO: DirtyRect に対応
                    surfaceBuffer.SetSurfaceData(e.Buffer, (uint)(e.Width * e.Height * 4));

                    UpdateLayeredWindowBitmap();
                }
                catch
                {

                }
            }
        }