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
Solved

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

Posted on 2001-08-21
12
152 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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