C# Bitmap class with matrix transformation (Shear 方法)

C# Bitmap class with matrix transformation (Shear method)

所以我想对位图使用矩阵变换class。

Matrix matrix = new Matrix();
matrix.Shear(0.1f, 30);

但我唯一能做的就是使用图形 class

    FileStream ifs = new FileStream(@"C:\Users\PC\Desktop\asd.png", FileMode.Open);
    Image image = Image.FromStream(ifs);
    Graphics g = Graphics.FromImage(image);
    g.Transform = matrix;

但是我如何将图形对象与位图一起使用。 我可以做到 Bitmap bitmap = new Bitmap(750,500,g); 但似乎图形对象并没有真正保留像素,而只保留了尺寸。关于如何将矩阵的剪切方法与位图(我的图像)一起使用有什么建议吗?

当您使用新的 Graphics 对象绘制某些内容时,您将获得所需的内容(剪切变换)。

因此,如果您只是创建一个新的位图并使用 DrawImage 在其上绘制现有的位图,您就大功告成了。

请注意,您必须自己计算新位图的预期大小。