Solved

how can I create a bitmap from a rich edit box

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now