Solved

how can I create a bitmap from a rich edit box

Posted on 1998-03-29
3
341 Views
Last Modified: 2013-12-03
I need to be able to create a bitmap from a rich edit box so I can avoid having to have my customers fonts on my machine so I can print their labels. I have tried copyrect but this requires a canvas on the control. My best bet seems to be paintto but I have had trouble grappling with device contexts.

My code to date is following. Hope someone out there can help.
var
bitmap:TBitmap;
dev:HDC;
begin
bitmap:=TBitmap.create;
try
dev:=bitmap.canvas.handle;
bitmap.height:=beamfrom.ClientHeight;
bitmap.width:=beamfrom.ClientWidth;
bitmap.pixelformat:=pfdevice;

beamfrom.paintto(dev,0,0);
beamto.Picture.Assign(bitmap);
finally
bitmap.free;
end;
end;
Regards Wayne Horrobin
0
Comment
Question by:whorrobin
  • 2
3 Comments
 

Accepted Solution

by:
Dippen earned 100 total points
ID: 1361003
Hi!

Try this code, which uses the form's canvas to copy the rich edit into a TImage and then to disk (written in D3):

procedure TForm1.Button1Click(Sender: TObject);
var
  Dest,
  Source : TRect;

begin
  Source.Top := richedit1.Top;
  Source.Left := richedit1.Left;
  Source.Bottom := (richedit1.Top + richedit1.Height);
  Source.Right := (richedit1.Left + richedit1.Width);
  Dest.Left := 0;
  Dest.Top := 0;
  Dest.Bottom := richedit1.Height;
  Dest.Right := richedit1.Width;
  image1.Height := richedit1.Height;
  image1.Width := richedit1.Width;
  image1.Canvas.CopyRect(Dest,form1.canvas,Source);
  image1.Picture.SaveToFile('Test.BMP');
end;


0
 

Expert Comment

by:Dippen
ID: 1361004
You could make the image invisible, it should work anyway...
0
 

Author Comment

by:whorrobin
ID: 1361005
Very much appreciate the help. Great to feel that you can get some help like this when you feel completely stonewalled. Top marks!

Regards Wayne Horrobin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 95
Delphi : could not find program, '...exe' 2 191
Help on VBSCript Font and color 1 110
Slow Restore if incremental backups using RDiff.exe 4 29
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question