Delphi的TCanvas CopyRect和Draw过程的C#等效项是什么? [英] What is the C# equivalent of Delphi's TCanvas CopyRect and Draw procedure?

查看:60
本文介绍了Delphi的TCanvas CopyRect和Draw过程的C#等效项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个非常老的Borland Delphi 3D旋转多维数据集应用程序转换为.NET 3.5上的C#.

我对GDI +非常不熟悉,似乎无法为Borland Delphi的Canvas CopyRect和Draw过程找到合适的C#实现解决方案.


C#代码:

I''m trying to convert a very old Borland Delphi 3D spinning cube application into C# on .NET 3.5

I''m very amateur with GDI+ and cannot seem to find a proper C# implementation solution for Borland Delphi''s Canvas CopyRect and Draw procedure.


C# code:

''DoubleBuffer'' and ''BlankBuffer'' are both of Bitmap class on a Windows.Form
...
this.graphics = this.CreateGraphics();

this.brush = new SolidBrush(Color.Black);

this.DoubleBuffer = new Bitmap(400, 400);
this.BlankBuffer = new Bitmap(400, 400);


//TO FIX
//this.BlankBuffer.Canvas.Draw(0, 0, BlankBuffer);

...和

...and

//TO FIX
//DoubleBuffer.Canvas.CopyRect(new Rectangle(0,0,400,400),BlankBuffer.Canvas,new Rectangle(0,0,400,400));


// TO FIX
//frmCube.Canvas.CopyRect(new Rectangle(0, 0, 400, 400), DoubleBuffer.Canvas, new Rectangle(0, 0, 400, 400));

推荐答案

您好,

几个月前,我遇到了同样的问题.我发现
Graphics.Drawimage确实可以正常工作以将图像的一部分复制到另一个位置:example

Hello,

I had the same problem a few months ago. I have found that
Graphics.Drawimage does work correctly to copy parts of an image at another place: example

Graphics g = Graphics.FromImage(mazeImage);
mazeElements.SetResolution(g.DpiX, g.DpiY)
g.DrawImage(mazeElements, 32 * x, 32 * y, new Rectangle(item * 32, 0, 32, 32), GraphicsUnit.Pixel);

g.Dispose();



这将从位图"mazeElements"中的矩形复制到位图"mazeImage"中的所需位置

警告:如果两个位图都不具有相同的Dpi,则存在舍入错误,如果将绘制的图像放置在偏移一个像素的位置,则可能会破坏结果.这就是"SetResolution"行的原因

希望对您有帮助



this will copy a rectangle from the bitmap "mazeElements" at the desired location in the bitmap "mazeImage"

WARNING: there are rounding errors that will possibly corrupt the results by putting the drawn image at a position shifted by one pixel if both bitmaps do not have the same Dpi. That''s the reason for the line with "SetResolution"

I hope this helps


这篇关于Delphi的TCanvas CopyRect和Draw过程的C#等效项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆