Files
RAGECOOP-V/Tools/CefTest/D2DWindow.cs

43 lines
1.2 KiB
C#
Raw Normal View History

2022-11-13 12:41:26 +08:00
using System;
2022-11-16 17:40:07 +08:00
using System.Windows.Forms;
2022-11-13 12:41:26 +08:00
using SharpD2D.Drawing;
using SharpD2D.Windows;
using SharpDX.Direct2D1;
using Image = SharpD2D.Drawing.Image;
namespace CefTest
{
2022-11-16 17:40:07 +08:00
public class D2DMedia : Control
2022-11-13 12:41:26 +08:00
{
private Canvas _canvas;
private Image _img;
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
Console.WriteLine("Initialize");
_canvas = new Canvas(Handle);
_canvas.SetupGraphics += _canvas_SetupGraphics;
_canvas.Initialize();
_canvas.DrawGraphics += _canvas_DrawGraphics;
}
private void _canvas_DrawGraphics(object sender, DrawGraphicsEventArgs e)
{
e.Graphics.BeginScene();
2022-11-16 17:40:07 +08:00
e.Graphics.DrawImage(_img, default(PointF));
2022-11-13 12:41:26 +08:00
e.Graphics.EndScene();
}
2022-11-16 17:40:07 +08:00
public void UpdateAndPaint(int width, int height, int pitch, IntPtr scan0, PixelFormat format)
2022-11-13 12:41:26 +08:00
{
2022-11-16 17:40:07 +08:00
_img.Update(width, height, pitch, scan0, format);
2022-11-13 12:41:26 +08:00
_canvas.SafeDraw();
}
2022-11-16 17:40:07 +08:00
2022-11-13 12:41:26 +08:00
private void _canvas_SetupGraphics(object sender, SetupGraphicsEventArgs e)
{
_img = e.Graphics.CreateImage();
}
}
}