Date: Sat, 23 Feb 2002 14:21:30 +0100 Newsgroups: borland.public.delphi.objectpascal Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Newsreader: Virtual Access by Atlantic Coast PLC, http://www.atlantic-coast.com/va Organization: TeamB Message-ID: Subject: Re: Creating a bitmap from form From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Reply-To: 100113.1101@compuXXserve.com References: <3c77077d_2@dnews> NNTP-Posting-Host: 172.179.87.129 X-Trace: dnews 1014470384 172.179.87.129 (23 Feb 2002 05:19:44 -0800) Lines: 67 Path: dnews Xref: dnews borland.public.delphi.objectpascal:229880 In article <3c77077d_2@dnews>, Rafael Cotta wrote: > I have a program that draws on Form.Canvas and use some TStaticText, and, > and a Memo that together form a picture. > How can I define a rectangle and save this as a bitmap (if I can save as > PNG, even better!). I mean, save what I can see as a bitmap, with memo, > canvas and statictext. You can create a canvas for the complete screen and copy a part of that to a bitmaps canvas. If you define the rectangle on the form (so in the forms client coordinates) you need to convert that to screen-relative coordinates. Example (untesed!): Procedure CopyFormrectToBitmap( aForm: Tform; aRect: TRect; aBitmap: TBitmap ); Var cv: TCanvas; Begin Assert( Assigned( aform )); Assert( Assigned( aBitmap )); cv:= TCanvas.Create; try cv.Handle := CreateDC( 'DISPLAY', Nil, Nil, Nil ); try MapWindowPoints( aForm.handle, HWND_DESKTOP, aRect, 2 ); aBitmap.Width := arect.right - arect.left; aBitmap.Height := arect.bottom - arect.top; aBitmap.Canvas.Copymode := cmSrcCopy; aBitmap.Canvas.CopyRect( aBitmap.Canvas.Cliprect, cv, aRect ); finally DeleteDC( cv.Handle ); cv.Handle := 0; End; { Try finally } Finally cv.free; End;{ Try finally } End; You need to pass an existing bitmap instance to the procedure, which you can then save to file. For PNG you need to find some conversion routine or component on the web. Search one of the sites below. http://www.borland.com/delphi/resources/deltools.html Delphi Super Page http://sunsite.icm.edu.pl/delphi/ US mirror site: http://www.cdrom.com/pub/delphi_www/ German mirror : http://ftp.uni-erlangen.de/pub/source/MIRRORS/sunsite.icm.edu.pl/pub/delphi Other mirrors : http://ftp.sunet.se/delphi/ Torry's Delphi Pages http://www.torry.net/ http://homepages.borland.com/torry/ the Delphi Box http://Inner-Smile.com . http://www.delphisource.com/ The DELPHI Deli http://www.delphix.com/ The Delphi EXchange http://www.delphiexchange.com/ The Delphi Pool http://www.lmc-mediaagentur.de/dpool.htm -- Peter Below (TeamB) 100113.1101@compuserve.com) No e-mail responses, please, unless explicitly requested! Use the newsgroup archives : http://www.mers.com/searchsite.html http://www.tamaracka.com/search.htm http://groups.google.com http://www.prolix.be