Writing Transparent Text on Image

前端 未结 7 1013
名媛妹妹
名媛妹妹 2020-12-16 05:54

How can I write a semi transparent text on an Image (Jpg,Bmp), or a transparent text (color as same background Image) but with a shadow, something I want to do to watermark

7条回答
  •  無奈伤痛
    2020-12-16 06:12

    The shadow is easy:

    // Bold shows up better when over an image
    image1.Canvas.Font.Style := [fsBold]; 
    // Write the shadow first
    image1.Canvas.Brush.Style:=bsClear;
    image1.Canvas.Font.Color := clGrayText;
    image1.Canvas.TextOut(1, 1, 'hi there');
    // Then put the text on top (slightly offset)
    image1.Canvas.Brush.Style:=bsClear;
    image1.Canvas.Font.Color :=clBlack;
    image1.Canvas.TextOut(0, 0, 'hi there');
    

    This is text with a transparent background. Or did you want the text itself to be simi-transparent? That is a little trickier. You would need to draw it manually. An easy way to do it instead would be to sample the average of the color of the area you are writing on the image. Then set your font color to be a little lighter and your shadow to be a little darker. Then it kind of blends in.

提交回复
热议问题