fix: transparency of icons (web side)

This commit is contained in:
Massimo Melina 2020-05-17 17:48:39 +02:00
parent 592607e23e
commit 24666f4dab

View File

@ -29,9 +29,9 @@ uses
Windows, Messages, SysUtils, Forms, Menus, Graphics, Controls, ComCtrls, Dialogs, math, Windows, Messages, SysUtils, Forms, Menus, Graphics, Controls, ComCtrls, Dialogs, math,
registry, ExtCtrls, shellapi, ImgList, ToolWin, StdCtrls, strutils, AppEvnts, types, registry, ExtCtrls, shellapi, ImgList, ToolWin, StdCtrls, strutils, AppEvnts, types,
winsock, clipbrd, shlobj, activex, Buttons, FileCtrl, dateutils, iniFiles, Classes, winsock, clipbrd, shlobj, activex, Buttons, FileCtrl, dateutils, iniFiles, Classes,
System.ImageList, system.Generics.Collections, System.ImageList, system.Generics.Collections, GIFimage,
// 3rd part libs. ensure you have all of these, the same version reported in dev-notes.txt // 3rd part libs. ensure you have all of these, the same version reported in dev-notes.txt
OverbyteIcsWSocket, OverbyteIcsHttpProt, GIFimage, regexpr, OverbyteIcsZLibHigh, OverbyteIcsZLibObj, OverbyteIcsWSocket, OverbyteIcsHttpProt, regexpr, OverbyteIcsZLibHigh, OverbyteIcsZLibObj,
// rejetto libs // rejetto libs
HSlib, traylib, monoLib, progFrmLib, classesLib; HSlib, traylib, monoLib, progFrmLib, classesLib;
@ -1952,56 +1952,58 @@ end;
function idx_label(i:integer):string; function idx_label(i:integer):string;
begin result:=intToStr(idx_img2ico(i)) end; begin result:=intToStr(idx_img2ico(i)) end;
function bmp2str(bmp:Tbitmap):ansistring; function gif2str(gif:TgifImage):ansistring;
var var
stream: Tbytesstream; stream: Tbytesstream;
gif: TGIFImage;
begin begin
{ the gif component has a GDI object leak while reducing colors of { the gif component has a GDI object leak while reducing colors of
{ transparent images. this seems to be not a big problem since the { transparent images. this seems to be not a big problem since the
{ icon cache system was introduced, but a real fix would be nice. } { icon cache system was introduced, but a real fix would be nice. }
stream:=Tbytesstream.create(); stream:=Tbytesstream.create();
gif:=TGIFImage.Create();
gif.ColorReduction:=rmQuantize;
gif.Compression:=gcLZW;
gif.Assign(bmp);
gif.SaveToStream(stream); gif.SaveToStream(stream);
setLength(result, stream.size); setLength(result, stream.size);
move(stream.bytes[0], result[1], stream.size); move(stream.bytes[0], result[1], stream.size);
gif.free;
stream.free; stream.free;
end; // gif2str
function bmp2str(bmp:Tbitmap):ansistring;
var
gif: TGIFImage;
begin
gif:=TGIFImage.Create();
try
gif.ColorReduction:=rmQuantize;
gif.Compression:=gcLZW;
gif.Assign(bmp);
result:=gif2str(gif);
finally gif.free;
end;
end; // bmp2str end; // bmp2str
function pic2str(idx:integer):ansistring; function pic2str(idx:integer):ansistring;
var var
pic, pic2: Tbitmap; ico: Ticon;
gif: TgifImage;
begin begin
result:=''; result:='';
if idx < 0 then exit; if idx < 0 then exit;
idx:=idx_ico2img(idx); idx:=idx_ico2img(idx);
if length(imagescache) < idx+1 then if length(imagescache) <= idx then
setlength(imagescache, idx+1); setlength(imagescache, idx+1);
result:=imagescache[idx]; result:=imagescache[idx];
if result > '' then exit; if result > '' then exit;
pic:=Tbitmap.create();
mainfrm.images.getBitmap(idx,pic);
// pic2 is the transparent version of pic
pic2:=Tbitmap.create();
pic2.Width:=mainfrm.images.Width;
pic2.height:=mainfrm.images.height;
pic2.TransparentMode:=tmFixed;
pic2.TransparentColor:=$2FFFFFF; ico:=Ticon.Create;
pic2.Transparent:=TRUE; gif:=TGifImage.Create;
BitBlt(pic2.Canvas.Handle, 0,0,16,16, pic.Canvas.Handle, 0,0, SRCAND); try
BitBlt(pic2.Canvas.Handle, 0,0,16,16, pic.Canvas.Handle, 0,0, SRCPAINT); mainfrm.images.getIcon(idx, ico);
gif.Assign(ico);
result:=bmp2str(pic2); result:=gif2str(gif);
pic2.free; imagescache[idx]:=result;
pic.free; finally
imagescache[idx]:=result; gif.Free;
ico.free;
end;
end; // pic2str end; // pic2str
function str2pic(s:ansistring):integer; function str2pic(s:ansistring):integer;
@ -2037,8 +2039,7 @@ if shfi.iIcon = 0 then
exit; exit;
end; end;
// as reported by official docs // as reported by official docs
if shfi.hIcon <> 0 then destroyIcon(shfi.hIcon);
destroyIcon(shfi.hIcon);
if sysidx2index = NIL then // firt time if sysidx2index = NIL then // firt time
sysidx2index:=Tint2int.Create(); sysidx2index:=Tint2int.Create();