Solved

How can i change the Text Backgraound color and save to Bmp

Posted on 2001-08-21
12
153 Views
Last Modified: 2010-04-06
Hello i can save text to bmp, is there a way during this process to save the text background to different colors
thanks
0
Comment
Question by:neopolis
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6408808
just fill it before you do your textout with fillrect
(adjust your brushcolor before)
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6408907
no need FillRect, TextOut is not transparent, so enough "adjust your brushcolor before".
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409057
yup, slavak, you're right, thats just enough :-)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:robert_marquardt
ID: 6409149
TextOut can be transparent or a TLabel could not be transparent.
So best set the whole background of your bitmap with a FillRect to the desired "paper" color.
If TextOut fills the background it will definitely only fill the rectangle of the written text with the current brush color. This is then the background color of the text.
So you end up with three colors. Text color, text background color and paper color.
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6409206
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409348
just if it from interest

a sample from my paq
paints a specific line (can contain various fonts and colors) from a richedit to a specific position
of a bitmap, which can have a picture on it


Procedure CopyLineFromRichEditToBitmap(R : TRichEdit;
                                       Line : Integer;
                                       B : TBitMap;
                                       AtPos : TPoint);
var
  I, C, MH, H, W : Integer;  //Counter, CharPos, MaxHeight, CharHeight, CharWidth
  TB, TB2 : TBitmap;         //Temporary Bitmaps
begin
  TB := TBitmap.Create;      //Create Temporary
  TB2 := TBitmap.Create;
  MH := 0;                   //Initialize
  H := 0;
  TB.Height := 100;
  TB.Width := 5;
  C := R.Perform(EM_LINEINDEX,Line,0);
  for I := 0 to Length(R.Lines[Line]) do  //Paint Line
  begin
    R.Selstart := C+I;
    R.SelLength := 1;
    TB.Canvas.Font.Assign(R.SelAttributes);  //Assign CharAttributes
    W := TB.Canvas.TextWidth(R.SelText);
    TB.Width := TB.Width + W;                //Expand Bitmap
    H := TB.Canvas.TextHeight(R.SelText);
    if MH < H then                           // MaxHeight
      MH := H;
    TB.Canvas.TextOut(TB.Width-W,50-h,R.SelText);  //Paint a Char
  end;
  TB2.Width := TB.Width - 5;  //adjust Painting Rect
  Tb2.Height := MH;
  TB2.Canvas.CopyRect(Rect(0,0,TB2.Width,TB2.Height),TB.Canvas,Rect(5,50-mh,tb.width,50));

  TB2.Transparent := True;   //Prepare
  TB2.TransparentMode := tmFixed;
  TB2.TransparentColor := clWhite;
  B.Canvas.Draw(AtPos.x,AtPos.Y,TB2);  //Paint to Original
  TB2.Free;  //Free Memory
  TB.Free;
end;

meikl ;-)
0
 

Author Comment

by:neopolis
ID: 6409417
All sounds like it works
sample code would be appreciated
i am new at this Slavak or Gwena gave me the Save text to bmp yesterday and that was good so if you can put the background color in there with it would be nice thanks
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 10 total points
ID: 6409443
just steeling the code from the q mentioned above

Bmp := TBitmap.Create;
Try
 With Bmp Do Begin
  Canvas.Font.Assign(Edit1.Font);
  Width  := Canvas.TextWidth(Edit1.Text);
  Height := Canvas.TextHeight(Edit1.Text);
  Canvas.Brush.Color := clRed;  //<-- add this line here, clRed is just a sample color
  Canvas.TextOut(0, 0, Edit1.Text);
  SaveToFile(FileName);
 End;
finally
 Bmp.Free;
end;


not tested

meikl ;-)
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6409459
meikl, if richedit (the line) visible, just copy it from the screen. It should be faster
0
 
LVL 3

Expert Comment

by:Slavak
ID: 6409474
meikl, if richedit (the line) visible, just copy it from the screen. It should be faster
0
 

Author Comment

by:neopolis
ID: 6409492
Thanks everyone nice fast response
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6409542
slavak,

would be not so easy,
if there are different sizes of the fonts are included,
because in this case i have also to calculate the copyrect from trichedits canvas.

but yes, it would be faster
and no, i would copy from the screen devicecontext,
which may cause in a not good quality

sorry for catching and modifying your code, slavak

glad to helped you neopolis

meikl ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
Controlled Assessment GCSE - desperate help needed 4 110
Delphi: Connect to running MS Outlook 4 157
Dynamically Created Query 3 69
Delphi Seattle StructureView color 1 21
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 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