Solved

how can I create a bitmap from a rich edit box

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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