Solved

how can I create a bitmap from a rich edit box

Posted on 1998-03-29
3
339 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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