GARANTIR DESCONTO

Fórum imagelist e listview #221592

23/03/2004

0

Olá

lá vai minha dúvida:

Como posso inserir icones no imagelist em runtime, pois os mesmo estarão com os respectivos caminhos salvos em arquivo *.ini, para posterior carregamento em uma listview

Obrigado!


Sanses

Sanses

Responder

Posts

23/03/2004

Sanses

sobe


Responder

Gostei + 0

23/03/2004

Marcelo Saviski

Veja se isso funciona:

imagelist.add(´Imagem.bmp´);



Responder

Gostei + 0

23/03/2004

Sanses

não funciona, dá esta mensagem:
incompatible types ´tbitmap´ and ´string´


Responder

Gostei + 0

23/03/2004

Aroldo Zanela

Colega,

Tenta esse aqui:

procedure SetImageListFromBmp(Bitmap: TBitmap;
  ImageList: TImageList; Width, Height, Images: integer);
var
  mask, image : TBitmap;
  R : TRect;
  cnt : integer;
begin
  Assert( (Bitmap <> nil) and Assigned(ImageList) );

  if Width < 1 then Width := Bitmap.Height;

  if Height < 1 then
    raise ERangeError.Create(´Height may not be less than 1´);

  if Bitmap.Width mod Width <> 0 then
    raise EInvalidOp.Create(´Bitmap width must be a multiple of Width´);
  if Bitmap.Height mod Height <> 0 then
    raise EInvalidOp.Create(´Bitmap height must be a multiple of Height´);

  ImageList.Clear;
  ImageList.Height := Height;
  ImageList.Width := Width;

  mask := TBitmap.Create;
  image := TBitmap.Create;
  try
    mask.Width := Width;
    mask.Height := Height;

    image.Width := Width;
    image.Height := Height;

    if Images < 1 then cnt := (Bitmap.Width div Width) +(Bitmap.Height
div Height)
      else cnt := Images;

    R := Rect(0, 0, Width, Height);
    while (cnt > 0) and (R.Bottom <= Bitmap.Height) do begin
      R.Left := 0;
      R.Right := Width;
      while (cnt > 0) and (R.Right <= Bitmap.Width) do begin
        image.Canvas.CopyRect(Rect(0,0,Width,Height), Bitmap.Canvas, R);

        mask.Assign(image); // lower left pixel
        mask.Canvas.Brush.Color := image.Canvas.Pixels[0, image.Height
-1];
        mask.Monochrome := true;

        ImageList.Add(image, mask);
        Dec(cnt);

        Inc(R.Left, Width);
        Inc(R.Right, Width);
      end;
      Inc(R.Top, Height);
      Inc(R.Bottom, Height);
    end;
  finally
    mask.Free;
    image.Free;
  end;
end;


Carregando:

MyBitmap.LoadFromFile( ´c:\somefile.bmp´ );
SetImageListFromBmp( MyBitmap, ImageList1, 0, MyBitmap.Height, 0 );



Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar