首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取ICO主色

获取ICO主色
EN

Stack Overflow用户
提问于 2011-09-22 04:33:25
回答 1查看 199关注 0票数 2

如何获取图标的主色?我使用的是delphi 2007

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-22 06:08:51

这是我在此基础上制作的一些混乱的代码,你应该找到一个最优的解决方案

代码语言:javascript
复制
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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7506267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档