首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ImgeEN中删除调色板中未使用的颜色

如何在ImgeEN中删除调色板中未使用的颜色
EN

Stack Overflow用户
提问于 2016-05-25 04:03:49
回答 1查看 292关注 0票数 1

我使用的是DelphiXE10中的ImageEN 5.2 (DCU版本)。

我想从颜色表(或相同的调色板)中删除UnUsed颜色,并使用此代码,但这不起作用:(

代码语言:javascript
复制
    procedure ConvertToOrdinal_8bit(PathToSave: string);
      var
        UsedColors: Integer;
        RGB_Palette: array of TRGB;
    begin
      with ImageEnView1 do
      begin
        UsedColors:= Proc.CalcImageNumColors;
        SetLength(RGB_Palette, UsedColors + 1);
        Proc.CalcImagePalette(RGB_Palette, UsedColors + 1);
        Proc.ConvertToPalette(UsedColors + 1, @RGB_Palette[0], ieOrdered);
        Refresh;
        Proc.Update;
        IO.Params.BitsPerSample := 8;
        IO.Params.SamplesPerPixel := 1;

        IO.SaveToFileBMP('c:\TestFile.bmp');
      end;
    end;

此调色板包含已使用的颜色和未使用的颜色

并且此调色板仅包含使用的颜色

EN

回答 1

Stack Overflow用户

发布于 2016-05-25 04:53:38

我建议将像素格式设置为ie8p,然后将TColorArray的长度设置为IEBitmap.PaletteLength,然后迭代IEBitmap.Palette以填充TColorArray,而不是删除不使用的颜色。

这将生成图像中的颜色列表。

代码语言:javascript
复制
uses ieview, imageenview, imageenproc, hyieutils, hyiedefs, exBitmaps, GraphUtil;

procedure TForm1.GetPaletteColors;
{ Fill TColorArray with palette colors. }
var
   i: Integer;
   iColorList: TColorArray;
begin
   ImageEnView1.IO.LoadFromFile(OpenPictureDialog1.FileName);
   { If the bitmap is not 8 bit paletted then convert it }
   if ImageEnView1.IEBitmap.PixelFormat <> ie8p then
      ImageEnView1.IEBitmap.PixelFormat := ie8p;
   SetLength(iColorList, ImageEnView1.IEBitmap.PaletteLength);
   { Add the colors to the TColorArray }
   for i := 0 to ImageEnView1.IEBitmap.PaletteLength - 1 do
   begin
      iColorList[i].Value := TRGB2TColor(ImageEnView1.IEBitmap.Palette[i]);
      iColorList[i].Name := '';
   end;
   { sort the colors by HUE - Optional}
   SortColorArray(iColorList, 0, 0, stHue, False);
end;

如果您需要更多帮助,可以从ImageEn的开发人员那里获得极好的支持:http://www.imageen.com/ieforum/forum.asp?FORUM_ID=11

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37422863

复制
相关文章

相似问题

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