Solved

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

Posted on 2001-08-21
12
149 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

16 Experts available now in Live!

Get 1:1 Help Now