gpt4 book ai didi

delphi - 获得ICO的主要颜色

转载 作者:行者123 更新时间:2023-12-03 18:43:16 27 4
gpt4 key购买 nike

如何获得图标的主要颜色?
我正在使用delphi 2007

最佳答案

这是我基于此编写的一些凌乱代码,您应该找到最佳解决方案

type
TElement = packed record
ocurrences: Integer;
color: TColor;
end;

Element = ^TElement;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
fname: string;
i, j, k, max: Integer;
lista_culori: TList;
tmp: TColor;
el: Element;
este: Boolean;
test: TIcon;
bmp: TBitmap;
begin
lista_culori := TList.Create;
if PromptForFileName(fname, '', '', '', '', false) then
begin
test := TIcon.Create;
bmp := TBitmap.Create;
test.LoadFromFile(fname);
bmp.Height := test.Height;
bmp.Width := test.Width;
bmp.Canvas.Draw(0, 0, test);
test.Free;
for i := 0 to bmp.Width do
for j := 0 to bmp.Height do
begin
tmp := bmp.Canvas.Pixels[i, j];
este := false;
for k := 0 to lista_culori.Count - 1 do
begin
if Element(lista_culori[k])^.color = tmp then
begin
el := Element(lista_culori[k]);
el^.ocurrences := el^.ocurrences + 1;
este := True;
el := nil;
end;
end;
if not este then
begin
GetMem(el, SizeOf(TElement));
el^.ocurrences := 0;
el^.color := tmp;
lista_culori.Add(el);
end;
end;
end;
max := Element(lista_culori[0])^.ocurrences;
k := 0;
for i := 1 to lista_culori.Count - 1 do
begin
if max < Element(lista_culori[i])^.ocurrences then
begin
k := i;
max := Element(lista_culori[i])^.ocurrences;
end;
end;
ShowMessage(ColorToString(Element(lista_culori[k])^.color));
end;

关于delphi - 获得ICO的主要颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7506267/

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