获取的exe图标生成TIcon对象,加入ImageList作为ListView的LargeImages属性,ListView的ViewStyle设置为vsIcon,为什么显示出来的图标有黑边(不透明)

ooolinux 2022-04-18 19:45:18

获取的exe图标生成TIcon对象,加入ImageList作为ListView的LargeImages属性,ListView的ViewStyle设置为vsIcon,为什么显示出来的图标有黑边(不透明)?用Image单独显示这个TIcon对象是正常的。

img

...全文
512 35 打赏 收藏 转发到动态 举报
写回复
用AI写文章
35 条回复
切换为时间正序
请发表友善的回复…
发表回复
ooolinux 2022-04-22
  • 打赏
  • 举报
回复

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
//窗体一个ListView,一个Image,一个ImageList,一个OpenDialog,一个Button
    this->ImageList1->Width=32;
    this->ImageList1->Height=32;
    this->ListView1->ViewStyle=vsIcon;
    this->ListView1->LargeImages=this->ImageList1;
    this->OpenDialog1->Filter=L"*.exe|*.exe";
    this->Button1->Caption=L"添加";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if (this->OpenDialog1->Execute())
    {
        HICON hIcon1;
        hIcon1 = ExtractIcon(HInstance, this->OpenDialog1->FileName.c_str(), 0);
        TIcon *Icon1 = new TIcon;
        Icon1->Handle = hIcon1;
        this->Image1->Picture->Icon = Icon1;
        this->Caption = IntToStr(Icon1->Width) + L" , " +
            IntToStr(Icon1->Height);
        this->ImageList1->AddIcon(Icon1);
        delete Icon1;
        TListItem *li=this->ListView1->Items->Add();
        li->ImageIndex=this->ImageList1->Count-1;
    }
}
//---------------------------------------------------------------------------

img

ooolinux 2022-04-22
  • 举报
回复
@ooolinux 老概试一下这个代码看看,我发现bcb.exe这种老软件的图标显示是正常的,阿里旺旺的图标Image显示正常,ListView显示就有黑边,这说明什么?
ooolinux 2022-04-23
  • 举报
回复
@ooolinux 问题解决了,ImageList1有颜色深度。
  • 举报
回复
@ooolinux 原来这么简单
1条回复
  • 打赏
  • 举报
回复

你左边的程序是用CB6写的吧,默认没有启用反锯齿,对比窗体上的文字最明显

ooolinux 2022-04-22
  • 举报
回复
@日立奔腾浪潮微软松下联想 原来是用CB6写的,后来升级到10.2。
  • 打赏
  • 举报
回复

img

ooolinux 2022-04-22
  • 举报
回复
@日立奔腾浪潮微软松下联想 有没有小巧一点的工具能查看group icon的?
  • 举报
回复
@ooolinux 不知道,我这电脑安装了vs,关联了.res,默认就用它打开了
ooolinux 2022-04-22
  • 举报
回复
@日立奔腾浪潮微软松下联想 vs太大了,我只有VS2013。
  • 打赏
  • 举报
回复

group icon是一个图标,里面有多个不同分辨率的图,用ExtractIcon、ExtractIconEx、ExtractAssociatedIcon、ExtractAssociatedIconEx都只能取到第一个图标。Delphi、CB高本版编译出的exe里默认带的图标就是group icon(一套5个图标),你用工具生成的图标应该也是这种。

ooolinux 2022-04-22
  • 举报
回复
@日立奔腾浪潮微软松下联想 就算是group icon(取出第一个),问题是Image显示正常,ListView显示有黑边,那个旺旺图标看得很明显,不知道是ImageList还是ListView的什么原因?
ooolinux 2022-04-22
  • 打赏
  • 举报
回复

img

ooolinux 2022-04-22
  • 举报
回复
@ooolinux 阿里旺旺的图标(只有1个)用ListView显示也有黑边。
ooolinux 2022-04-22
  • 打赏
  • 举报
回复

// ---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

// ---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
    this->Button2->Enabled = false;
}

// ---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if (this->OpenDialog1->Execute())
    {
        fileName = this->OpenDialog1->FileName;
        total = (int)ExtractIcon(HInstance, fileName.c_str(), -1);
        this->Caption = L"共有" + IntToStr(total) + L"个图标";
        i = 0;
        this->Image1->Picture = NULL;
        this->Button2->Enabled = true;
    }
}

// ---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
    if (i < total)
    {
        HICON hIcon1;
        hIcon1 = ExtractIcon(HInstance, fileName.c_str(), i);
        TIcon *Icon1 = new TIcon;
        Icon1->Handle = hIcon1;
        this->Image1->Picture->Icon = Icon1;
        this->Caption = IntToStr(Icon1->Width) + L" , " +
            IntToStr(Icon1->Height);
        delete Icon1;
        ++i;
        if (i >= total)
            this->Button2->Enabled = false;
    }
}
// ---------------------------------------------------------------------------

ooolinux 2022-04-22
  • 举报
回复
@ooolinux 我用这个代码,那个exe是只有一个图标的,其它exe(比如bcb.exe)有多图标的,获取的都是32x32。
ooolinux 2022-04-20
  • 打赏
  • 举报
回复

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if (this->OpenDialog1->Execute())
    {
        HICON hIcon1;
        hIcon1 = ExtractIcon(HInstance, this->OpenDialog1->FileName.c_str(), 0);
        TIcon *Icon1 = new TIcon;
        Icon1->Handle = hIcon1;
        this->Image1->Picture->Icon = Icon1;
        this->Caption = IntToStr(Icon1->Width) + L" , " +
            IntToStr(Icon1->Height);
        delete Icon1;
    }
}
// ---------------------------------------------------------------------------

  • 举报
回复
@ooolinux 有多个不同分辨率的图标,这代码只取到了第一个
ooolinux 2022-04-22
  • 举报
回复
@日立奔腾浪潮微软松下联想 贴了新代码
  • 举报
回复
@日立奔腾浪潮微软松下联想 图标可以是group icon,里面有多个icon,可以用tdump/tdump64看一下输出
1条回复
ooolinux 2022-04-20
  • 打赏
  • 举报
回复

img

ooolinux 2022-04-20
  • 举报
回复
@ooolinux 右边资源管理器显示的,左边是Rolan软件。
  • 举报
回复
@ooolinux 看起来是有多个不同分辨率的图标,你取的可能是第一个,可以EnumResourceNames,然后LoadIcon
ooolinux 2022-04-20
  • 举报
回复
@日立奔腾浪潮微软松下联想 这个图标是我用png在图标网站转换生成128x128的ico,我用那个代码获取的不管什么图标包括word都是32x32的,资源管理器显示的就要大一些。
2条回复
  • 打赏
  • 举报
回复

icon格式是支持透明的,有一个xor mask和一个and mask,看你的图,左边listview里显示的很可能是原图,右边的可能缩放显示时做了平滑处理(反锯齿)

ooolinux 2022-04-20
  • 举报
回复
@日立奔腾浪潮微软松下联想 我贴了资源管理器显示的图,是透明的
  • 打赏
  • 举报
回复

也许绘制时做了平滑处理?改一下背景色试试

ooolinux 2022-04-19
  • 举报
回复
@日立奔腾浪潮微软松下联想 我试一下
ooolinux 2022-04-19
  • 举报
回复
@日立奔腾浪潮微软松下联想 exe原始图标文件的背景色?
ooolinux 2022-04-19
  • 举报
回复
@ooolinux 还是ImageList的属性?
ooolinux 2022-04-18
  • 打赏
  • 举报
回复

这是网上的获取exe图标的代码:
HICON hIcon;
// Total =(int) ExtractIcon( Form1->Handle, FileName.c_str(), -1);
TIcon *Icon = new TIcon();
hIcon = ExtractIcon( Form1->Handle, FileName.c_str(), 0);
Icon->Handle=hIcon;

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧