zoukankan      html  css  js  c++  java
  • XE5 ImageList的BUG?

    今天做界面, 在imagelist里加载一个带有半透明通道的PNG图, 结果发现图片居然发暗, 如下:

    原图: IDE里加载以后的图:

    明显变暗...查询了源码, 无果

    然后又用2010去测试, 发现没问题...可惜2010版本看不到ImageListEditer的源码, 所以无从比较

    随后我又用代码去动态加载图片, 发现仍然会有图片变暗的问题:

    var
      nWIC: TWICImage;
      nBmp: TBitmap;
    begin
      nWIC := TWICImage.Create;
      nWIC.LoadFromFile('d:542725.png');
    
      nBmp := TBitmap.Create;
      nBmp.Assign(nWIC);
    
      ImageList1.Add(nBmp, nil);
      nBmp.Free;
      nWIC.Free;
    end;

    继续查找源码, 经过1个多小时的各种郁闷, 终于发现了一个以前被忽略过的属性: nBmp.AlphaFormat

    从帮助上看到其描述:

    Vcl.Graphics.TAlphaFormat

    From RAD Studio API Documentation
     

    Delphi

    TAlphaFormat = (afIgnored, afDefined, afPremultiplied);

    C++

    enum DECLSPEC_DENUM TAlphaFormat : unsigned char { afIgnored, afDefined, afPremultiplied };

    Properties

    TypeVisibilitySourceUnitParent
    enum public
    Vcl.Graphics.pas
    Vcl.Graphics.hpp
    Vcl.Graphics Vcl.Graphics

    Description

    TAlphaFormat indicates how the reserved byte of each pixel is used in a 32 bit bitmap.

    TAlphaFormat has the following values:

    ValueMeaning

    afIgnored

    The Reserved byte in the TRGBQuad is ignored.

    afDefined

    The reserved byte in the TRGBQuad contains an alpha value.

    afPremultiplied

    The reserved byte in the TRGBQuad contains an alpha value. The red, green, and blue values have been premultiplied with the alpha value.

    似乎应该使用afDefined值, 可以让BMP理解透明通道的值, 可是写了测试代码, 却无效果

    试试其他的值, 发现使用afIgnored的时候是正常的...-_- 不知道为啥

    var
      nWIC: TWICImage;
      nBmp: TBitmap;
    begin
      nWIC := TWICImage.Create;
      nWIC.LoadFromFile('d:542725.png');
    
      nBmp := TBitmap.Create;
      nBmp.Assign(nwic);
      nBmp.AlphaFormat := afIgnored;
    
      ImageList1.Add(nbmp, nil);
      nBmp.Free;
      nWIC.Free;
    end;

    可惜在IDE界面里, 直接使用编辑器向ImageList添加图像仍然是灰色的, 无解....只好通过代码从资源文件中加载了.....先这么办吧

  • 相关阅读:
    IP寻址方式三
    IP通信基础4
    IP通信基础3
    IP通信基础2
    IP通信基础 1
    IP通信基础
    IP通信原理第二周
    设备选型
    常用virsh命令记录
    [转]enable spice html5 console access in openstack kilo(centos)
  • 原文地址:https://www.cnblogs.com/lzl_17948876/p/4272916.html
Copyright © 2011-2022 走看看