TsAlphaImageList.LoadFromResource

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #32968
    xeper
    Participant

    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
    // TsImgListItem

    procedure 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;

    #39340
    Support
    Keymaster

    Thanks for offer.
    Such feature is added in the ToDo list and will be made soon, I think.

    #39642
    Support
    Keymaster

    In 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);

    #39666
    xeper
    Participant

    Thank you very much.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.