Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
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));
Posted
Updated 1-Sep-10 2:30am
v2

1 solution

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

MIDL
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();


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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900