Solved

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

Posted on 2001-08-21
12
151 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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