How to work with TsAlphaImageList at runtime?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #34911
    ralfiii
    Participant

    I want to add some png-images at runtime to a TsAlphaImageList.

    I tried the following code:

    Code:
    strm:=TFileStream.Create(JvFilenameEdit1.Text, fmOpenRead or fmShareDenyNone);
    with TsImgListItem(sAlphaImageList1.Items.Add) do
    begin
    ImageFormat := ifPNG;
    PixelFormat := pf32bit;
    ImgData.LoadFromStream(strm);
    end;
    strm.Free;

    For some reason it doesn't work, ImageList.Count doesn't change.

    And one more: TsAlphaImageList.Clear doesn't work.

    To verify:

    Add a TsAlphaImageList to a form, all an images into the imagelist and the following code to a button:

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Caption:=IntTostr(sAlphaImageList1.Count);
    sAlphaImageList1.Clear;
    Caption:=Caption+' – '+IntTostr(sAlphaImageList1.Count);
    Exit;

    result “1 – 1”

    With TImageList: “1 – 0”.

    HELP!

    Thanks!

    Ralf

    #47246
    Support
    Keymaster

    Hello

    Try such code

    Code:
    sAlphaImageList1.Clear;
    sAlphaImageList1.Items.Clear;
    sAlphaImageList1.AcBeginUpdate;
    strm:=TFileStream.Create(JvFilenameEdit1.Text, fmOpenRead or fmShareDenyNone);
    with TsImgListItem(sAlphaImageList1.Items.Add) do
    begin
    ImageFormat := ifPNG;
    PixelFormat := pf32bit;
    ImgData.LoadFromStream(strm);
    end;
    strm.Free;
    sAlphaImageList1.AcEndUpdate(True {ImgList updated here if True});

    Maybe this demo will be interested for you :

    http://www.alphaskin…lyphsinskin.zip

    #47249
    ralfiii
    Participant

    This code doesn't do anything good.

    For adding images I found a solution:

    Code:
    with TsImgListItem(imgList.Items.Add) do
    begin
    ImageFormat := ifPNG;
    PixelFormat := pf32bit;
    ImgData.LoadFromStream(strmBinInDb);

    Png := TPNGGraphic.Create;
    Png.LoadFromStream(ImgData);
    Ico := MakeIcon32(Png);
    ImageList_AddIcon(imgList.Handle, Ico);
    DestroyIcon(Ico);
    FreeAndNil(Png);
    end;

    (…quite a lot of code…)

    but Clear still doesn't work at all.

    #47272
    Support
    Keymaster
    'ralfiii' wrote:
    but Clear still doesn't work at all.

    You uses this code?

    Code:
    sAlphaImageList1.Clear;
    sAlphaImageList1.Items.Clear;
    #47273
    ralfiii
    Participant

    Yes, I used

    Code:
    Caption:=IntTostr(sAlphaImageList1.Count);
    sAlphaImageList1.Clear;
    sAlphaImageList1.Items.Clear;
    Caption:=Caption+' – '+IntTostr(sAlphaImageList1.Count);

    And the result is “2 – 2”.

    So before and after 2 images.

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