因此,我在程序(Windows表单)上创建了一些矢量图形。现在,我想将它们倒置并粘贴在控件上其他地方的倒置部分。我当然会沿相反的方向绘制所有图形,但是它会非常麻烦且复杂,因此我决定简单地复制存在所需图纸的屏幕区域,然后水平倒转并将其粘贴到我的目标上点 到目前为止,我有了AI协作:
private static void InvCopy(Graphics g, Rectangle source, Point destination)
{
Bitmap copiedImg = new Bitmap(source.Width, source.Height);
using (Graphics copiedGraphics = Graphics.FromImage(copiedImg))
{
copiedGraphics.DrawImage(copiedImg,source);
}
copiedImg.RotateFlip(RotateFlipType.RotateNoneFlipX);
g.DrawImage(copiedImg, destination);
}
它不会丢下任何错误,但是当我使用它为:
时,它也不会在屏幕上发布任何错误
InvCopy(graphics,source,destination);
我在这里做错了什么,我该如何解决?
ok,因此我最终能够解决我的问题解决方案。它与Meta AI和Chatgpt一起来回了一些,但最后我一切都顺利进行。这是方法的工作方式:
public static void InvCopy(Graphics targetGraphics, int formX, int formY, int x1, int y1, int x2, int y2, int pasteX, int pasteY)
{
// Calculate the absolute screen coordinates of the rectangle to capture
Rectangle rect = new Rectangle(x1, y1, x2 - x1, y2 - y1);
Point screenLocation = new Point(formX + rect.Left, formY + rect.Top); // Convert form coordinates to screen coordinates
// Create a bitmap to store the captured image
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
// Capture the screen area into the bitmap (using the calculated screen coordinates)
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(screenLocation.X, screenLocation.Y, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
}
// Flip the captured image horizontally
Bitmap flippedBmp = new Bitmap(bmp.Width, bmp.Height);
using (Graphics g = Graphics.FromImage(flippedBmp))
{
g.ScaleTransform(-1, 1); // Flip horizontally
g.DrawImage(bmp, new Point(-bmp.Width, 0)); // Draw at the flipped position
}
// Paste the flipped image at the new position
targetGraphics.DrawImage(flippedBmp, pasteX, pasteY);
}
由于将其带到了图形对象,因此可以在项目中的任何地方使用,并且不限于包含相关代码的模块上使用。