- This topic has 3 replies, 2 voices, and was last updated 15 years, 5 months ago by xeper.
-
AuthorPosts
-
May 18, 2009 at 3:36 pm #32968xeperParticipant
Hi,
ImageLists usually can load from resources but as far as I understand, TsAlphaImageList cannot do that. As I needed it badly, I attempted to write such proc. It was written on 6.05, but it apparently works on 6.23 also (although I don't know why: I get lost in TsAlphaImageList … design ;-).
My proc works only for icons. If it's possible, please “upgrade” and include in upcoming releases. Code is in two places (one proc in TsImgListItem, second in TsAlphaImageList). Here it goes:
CODE// TsImgListItemprocedure TsImgListItem.ProcessIcon(anIcon: HICON);
Var
Icon : TIcon;
iInfo : TIconInfo;
BmpLine : PRGBAArray;
Y, X : Integer;
begin
// TODO sprawdzić
ImgData.Clear;
FImageFormat := ifICO;
if anIcon = 0 then Exit;
Icon := TIcon.Create;
try
Icon.Handle := anIcon;
Icon.SaveToStream(ImgData);
ImgData.Position := 0;
GetIconInfo(anIcon, iInfo);
with TBitmap.Create do try
Handle := iInfo.hbmColor;
HandleType := bmDIB;
Self.PixelFormat := PixelFormat;
// 6.23
if (PixelFormat = pf32bit) then begin // Check the alpha channel
for Y := 0 to Height – 1 do begin
BmpLine := ScanLine[Y];
for X := 0 to Width – 1 do begin
if BmpLine[X].A <> 0 then begin
Self.PixelFormat := pf32bit;
Break;
end;
end;
if Self.PixelFormat = pf32bit then Break;
end;
end;
finally
Free;
DeleteObject(iInfo.hbmColor);
DeleteObject(iInfo.hbmMask);
end;
finally
Icon.Free;
end;
end;// TsAlphaImageList
function TsAlphaImageList.AddFromResources(aInstance: LongWord; ResName: String): Boolean;
Var
hIc : HICON;
begin
Result := False;
hIc := LoadImage(aInstance, PChar(ResName), IMAGE_ICON, Width, Height, 0);
if hIc = 0 then Exit;
try
if ImageList_AddIcon(Handle, hIc) <> -1 then begin
(Items.Add as TsImgListItem).ProcessIcon(hIc);
Result := True;
end;
finally
DestroyIcon(hIc);
end;
end;May 25, 2009 at 2:27 pm #39340SupportKeymasterThanks for offer.
Such feature is added in the ToDo list and will be made soon, I think.June 18, 2009 at 10:20 am #39642SupportKeymasterIn the latest release was added the new function AddImageFromRes(aInstance: LongWord; ImageList : TsAlphaimageList; const ResName: String; ImageFormat : TsImageFormat): Boolean;
This function is not a method of the AlphaImageList object, implemented as separated function. Please check it, may be added Ico and Png there.
TsImageFormat = (ifPNG, ifICO);June 21, 2009 at 4:51 pm #39666xeperParticipantThank you very much.
-
AuthorPosts
- You must be logged in to reply to this topic.