I believe canvas.release causes the problem.
Code:
var
Form1: TForm1;
Surface : TDirectDrawSurface;
NewSurface : TDirectDrawSurface;
implementation
{$R *.dfm}
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
begin
Form1.DXDraw1.Surface.Draw(0,0, Surface.ClientRect, Surface, false);
Form1.DXDraw1.Surface.Draw(100, 300, NewSurface.ClientRect, NewSurface, false);
Form1.DXDraw1.Flip;
end;
procedure copyTOImagelist();
begin
newSurface.Canvas.CopyRect(rect(0,0,100,100), surface.Canvas, rect(150,50,250,150) );
newSurface.Canvas.CopyRect(rect(100,0,200,100), surface.Canvas, rect(150,350,250,450) );
newSurface.Canvas.Release;
end;
procedure TForm1.DXDraw1Initialize(Sender: TObject);
begin
Surface := TDirectDrawSurface.Create(DXDraw1.DDraw);
Surface.LoadFromGraphic(Form1.DXImagelist1.items.items[0].picture.graphic);
NewSurface := TDirectDrawSurface.Create(DXDraw1.DDraw);
NewSurface.SetSize(200,100); //set default size;
NewSurface.Fill(0); //set default color;
end;
procedure TForm1.DXDraw1Finalize(Sender: TObject);
begin
Surface.free;
NewSurface.free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
copyTOImagelist
end;
end.
The above code creates 2 surfaces. The first loads an image at startup. If, at runtime the user presses the button it will load two smaller portions of the first surface into the second surface.
After that you can either save it to a file or load it into another list.
Bookmarks