【发布时间】:2019-12-12 04:56:46
【问题描述】:
我正在尝试从输入的方形图像制作具有透明背景的倾斜图像。
到目前为止,倾斜部分正在工作,但未倾斜图像的背景仍然存在。如何从背景中删除未倾斜的图像并将其替换为透明背景?
到目前为止,我已经尝试过使用.Clear(Color.Transparent),但它似乎只能使整个图像清晰或什么都不做。
到目前为止的代码:
using System;
using System.Drawing;
class Program
{
static void Main(string[] args)
{
Point[] destinationPoints = {
new Point (150, 20),
new Point (40, 50),
new Point (150, 300)
};
Image before = Image.FromFile(System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"before.png"));
var gr = Graphics.FromImage(before);
//drawing an ellipse
Pen myPen = new Pen(Color.Red);
gr.DrawEllipse(myPen, new Rectangle(0, 0, 200, 300));
//applying skewed points
gr.DrawImage(before, destinationPoints);
var path = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"after.png");
before.Save(path);
}
}
之前.png
之后.png
粗略的预期结果
【问题讨论】:
-
您的问题解决了吗?