gpt4 book ai didi

delphi - 如何绘制文本居中的纯色位图?

转载 作者:行者123 更新时间:2023-12-02 11:02:02 32 4
gpt4 key购买 nike

下面的代码应该创建一个位图,该位图是一个 48x48 矩形、蓝色背景和水平和垂直居中的白色文本(实际上只是一个字母)。

但是什么也没发生。

procedure MakeCustomIcon(AText: string; AWidth: Integer; AHeight: Integer; AColor: TAlphaColor; var ABlob: TBlob);
var
Bitmap: TBitmap;
Rect: TRectF;
InStream: TMemoryStream;
begin
Bitmap := TBitmap.Create;
InStream := TMemoryStream.Create;
try
Bitmap.SetSize(AWidth, AHeight);

Bitmap.Canvas.Clear(AColor);

Bitmap.Canvas.Stroke.Kind := TBrushKind.bkSolid;
Bitmap.Canvas.StrokeThickness := 1;
Bitmap.Canvas.Fill.Color := TAlphaColorRec.White;
Bitmap.Canvas.BeginScene;

Rect.Create(0, 0, AWidth, AHeight);
Bitmap.Canvas.FillText(Rect, AText, true, 100, [TFillTextFlag.ftRightToLeft], TTextAlign.taCenter, TTextAlign.taCenter);

Bitmap.Canvas.EndScene;

Bitmap.SaveToStream(InStream);

InStream.Position := 0;

ABlob.Clear;
ABlob.LoadFromStream(InStream);
finally
Bitmap.Free;
InStream.Free;
end;

我已经测试了程序的其余部分,以确保图像(Blob)确实正在传输和显示,而且它正在这样做。问题完全包含在上面方法中绘制位图的方式上。

这个 TBlob 是一个字节数组。

我正在寻找像下面这样的矩形,以在 TListView 中使用:

this

最佳答案

我已经准备好了一个项目。

1-) 在 TImage 上写入文本

2-) 在 TImage 上绘图

3-) 对 TImage 的效果

我尝试XE5

示例:

procedure ReDraw(Image: TImage);
var
MyRect: TRectF;
begin
if Image.Bitmap.IsEmpty then Exit;

MyRect := TRectF.Create(0, Ozellik.SeritTop, Image.Bitmap.Width, Ozellik.SeritBot);
with Image.Bitmap.Canvas do
begin
BeginScene;
if not Seffaf.IsChecked then
Fill.Color := Ozellik.SeritRenk
else
Fill.Color := TAlphaColorRec.Null;
FillRect(MyRect, 0, 0, [], 1);
Fill.Color := Ozellik.YaziRenk;
if FontCombo.ItemIndex <> -1 then
Font.Family := FontCombo.Items[FontCombo.ItemIndex];
Font.Size := Ozellik.YaziBoyut;
FillText(MyRect,FonYazi.Text.Trim,True,1,[],TTextAlign.taCenter,TTextAlign.taCenter);
EndScene;
end;
Image.Repaint;
end;

http://www.dosya.tc/server32/vHsbaC/CapsYapMasa_st_.rar.html

enter image description here

enter image description here

关于delphi - 如何绘制文本居中的纯色位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25418772/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com