是否可以通过 Script# 或其他 C# 到 JS 转换器分别将标准System.Drawing.Graphics
方法(如DrawImage
、DrawPath
和其他方法)转换为 html5 canvas 方法(如context.drawImage
和context.beginPath(); ... context.closePath();
)?
编译后如何自动执行此操作而无需.js文件编辑?
我遇到了同样的问题。
在画布上绘制的方式与使用 System.Drawing.Graphics 的方式并不完全相同。一个解决方案是在System.Drawing.Graphics上创建一个抽象,如下所示:
public interface IDrawingContext{
void Save();
void Restore();
void DrawLine(int x1, int y1, int x2, int y2, string color, int strokeWidth);
void DrawText(int x, int y, string text, string color);
object DrawRect(int x, int y, int width, int height, object fill, string strokeColor);
object DrawPoly(List<Coordinate> points, object fill, string strokeColor, int strokeWidth);
object DrawCircle(int x, int y, int radius, object fill, string strokeColor);
object Transform(int translateX, int translateY, int rotate);
.
.
.
void Clear();
}
在 script# 中创建一个实现此接口的类,并使用 script# System.Html.Media.Graphics 命名空间对画布进行本机调用。 在 C# 项目中执行相同的操作,但使用 System.Drawing.Graphics
接下来是重构现有的绘图代码,以使用IDrawingContext而不是System.Drawing.Graphics