Solved

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

Posted on 2001-08-21
12
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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