2016-04-14 25 views

cevap

2
var 
    Size: TSizeF; 
begin 
    Size := TSize.Create(64,64) 
    Bitmap1.Assign(Imagelist1.Bitmap(Size, Index)); 
end 
+0

nolaspeaker sayesinde kullanabilirsiniz. Ama bir speedbuttonda bitmap1'i nasıl yüklerim? –

+0

Speedbutton'un bir .Imageindex özelliği vardır, sadece SpeedButton'un .Images özelliğini atadığınızdan sonra, özellik düzenleyicisinden birini seçin. (VCL'de olduğu gibi) – nolaspeaker

+0

nolaspeaker, Üzgünüm, kodunuzun nasıl çalıştığını göremiyorum. Eğer programsal olarak her şeyi yapmak istersem, bir ImageList oluşturmam, bir bitmap yüklemem ve daha sonra görüntüleyiciyi speedbuttona atamam ve sonra speedbutton'da görüntülenecek olan görüntüyü seçmem gerekiyor. Yapmam gereken şey bu. Kodunuz, bir görüntü sağlayıcıdan bir bitmap'e bir resim atadı –

1

TSpeedButton'da, Images ve ImageIndex'i ayarlamanız gerekir. Eğer AddOrSet kullanabilirsiniz TImageList içine resimlerini yüklemek için veya bu örnekte bunun için

procedure TForm11.Button2Click(Sender: TObject); 
const 
    SourceName = 'Картинка'; 
    procedure LoadPicture(const Source: TCustomSourceItem; const Scale: Single; const FileName: string); 
    var 
    BitmapItem: TCustomBitmapItem; 
    TmpBitmap: TBitmap; 
    begin 
    BitmapItem := Source.MultiResBitmap.ItemByScale(Scale, True, True); 
    if BitmapItem = nil then 
    begin 
     BitmapItem := Source.MultiResBitmap.Add; 
     BitmapItem.Scale := Scale; 
    end; 
    BitmapItem.FileName := FileName; 
    TmpBitmap := BitmapItem.CreateBitmap; 
    try 
     if TmpBitmap <> nil then 
     BitmapItem.Bitmap.Assign(TmpBitmap); 
    finally 
     TmpBitmap.Free; 
    end; 
    end; 
var 
    NewSource: TCustomSourceItem; 
    NewDestination: TCustomDestinationItem; 
    NewLayer: TLayer; 
begin 
    if ImageList1.Source.IndexOf(SourceName) = -1 then 
    begin 
    NewSource := ImageList1.Source.Add; 
    NewSource.Name := SourceName; 
    NewSource.MultiResBitmap.TransparentColor := TColorRec.Fuchsia; 
    NewSource.MultiResBitmap.SizeKind := TSizeKind.Custom; 
    NewSource.MultiResBitmap.Width := 16; 
    NewSource.MultiResBitmap.Height := 16; 
    LoadPicture(NewSource, 1, 'D:\Мои веселые картинки\Icons\16x16\alarm16.bmp'); 
    LoadPicture(NewSource, 1.5, 'D:\Мои веселые картинки\Icons\24x24\alarm24.bmp'); 
    NewDestination := ImageList1.Destination.Add; 
    NewLayer := NewDestination.Layers.Add; 
    NewLayer.SourceRect.Rect := TRectF.Create(TPoint.Zero, NewSource.MultiResBitmap.Width, 
     NewSource.MultiResBitmap.Height); 
    NewLayer.Name := SourceName; 
    ControlAction1.ImageIndex := NewDestination.Index; 
    end; 
end;