Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Cannot Assign TBitmapCanvas to TBitmapCanvas (https://www.delphipraxis.net/64050-cannot-assign-tbitmapcanvas-tbitmapcanvas.html)

sk.Silvia 26. Feb 2006 18:45


Cannot Assign TBitmapCanvas to TBitmapCanvas
 
hi alle:)

ich hab probleme mit diesen part fo code

Delphi-Quellcode:
 
  procedure TEngine.Show;
  var tmp:TBitmap;
      begin
      tmp:=TBitmap.Create;
      tmp.Canvas.Assign(Screen.Canvas);

      ShowScr.Canvas.Draw(-10,-10,tmp);
      ShowScr.Canvas.LineTo(50,50);
      end;
it creates a runtime error "Cannot Assign TBitmapCanvas to TBitmapCanvas" what is nonesence..isnt it??
i just only want to save the canvas into TBitmap (and dont want to make it over Pixels[], cuz its too slow)

Dust Signs 26. Feb 2006 18:49

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
You could use CopyRect or BitBlt instead. And don't forget to free the tmp bitmap ;)

Dust Signs

sk.Silvia 26. Feb 2006 19:29

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
ok i used

Delphi-Quellcode:
ShowScr.Canvas.CopyRect(ShowScr.Canvas.ClipRect,Screen.Canvas,Screen.ClientRect);
thats fine, but only in the case that ShowScr is the same size (width, height) as Screen, when not i get enlarged picture:(

Dust Signs 26. Feb 2006 19:33

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
Well, why do you work with the ShowScr's cliprect then? Your method only works if the two cliprects are exactly equal (if you don't want to have anything enlarged ;))

Dust Signs

marabu 26. Feb 2006 19:47

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
Hi Silvia,

Zitat:

Zitat von sk.Silvia
i just only want to save the canvas into TBitmap

you can do that and more when you pick up GrabImage() over there: klick

Delphi-Quellcode:
procedure TDemoForm.GrabButtonClick(Sender: TObject);
begin
  with GrabImage(GetDesktopWindow) do
  begin
    if SaveDialog.Execute then
      SaveToFile(SaveDialog.FileName);
    Free;
  end;
end;
Kind regards

marabu

sk.Silvia 26. Feb 2006 19:58

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
i know, but its doing the same with ClinetRect, i try to do the following

http://www.politea.sk/mpp01.jpg

the screen canvas i only work woth (isnt displayed) and diplayed is only ShowScr which contains a part of Screen.Canvas

marabu 26. Feb 2006 20:50

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
Your choice of variable names confused me. Screen is a well known VCL management object and has no canvas property. It seems you have two bitmaps - one to hold a full image and one to hold an arbitrary rect cut out of the full image. CopyRect would be my choice to accomplish this. The code for ClipButtonClick is my test code:

Delphi-Quellcode:
procedure GetViewPort(bmFull, bmPart: TBitmap; TopLeft: TPoint);
var
  r: TRect;
begin
  with bmPart do
    r := Bounds(TopLeft.X, TopLeft.Y, Width, Height);
  with bmPart.Canvas do
    CopyRect(ClipRect, bmFull.Canvas, r);
end;

procedure TDemoForm.ClipButtonClick(Sender: TObject);
var
  bmFull: TBitMap;
begin
  bmFull := GrabImage(GetDesktopWindow);
  with Image.Picture.Bitmap do
  begin
    Width := Image.Width;
    Height := Image.Height;
  end;
  GetViewPort(bmFull, Image.Picture.Bitmap, Point(100, 100));
  bmFull.Free;
end;
marabu

sk.Silvia 27. Feb 2006 19:24

Re: Cannot Assign TBitmapCanvas to TBitmapCanvas
 
thank you :hello: :spin: :kiss:


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:11 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz