Autor |
Beitrag |
LonghornUser
Beiträge: 796
|
Verfasst: Mo 24.04.06 13:59
Hallo,
ich möchte einer Zelle in einer Grid-Komponente eine Grafik zuweisen. Das geht auch. Aber nur aus einer BMP-Datei und nicht aus einer ImageList. Da ich nicht alles doppelt einbinden will, da ich momentan alle Grafiken in einer ImageList habe, wollte ich fragen, ob man ImageList-Einträge in einen Stream laden kann und diesen dann der Zelle zuweisen kann.
Von eienr Datei laden geht bei der Komponente so:
Delphi-Quelltext 1: 2: 3: 4: 5: 6:
| var G: TGraphic; begin G := TBitmap.Create; G.LoadFromFile('testbitmap.bmp'); GridView1.Cell[0,0].ObjectReference := G; end; |
Danke schonmal.
Ciao LHUser
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 24.04.06 14:19
Moin!
Mach´s andersrum: pack in die .Objects[] den Index in die ImageList (Typecast auf TObject für rein und auf Integer beim Lesen) und Zeichne im OnDraw per TImageList.Draw() das Ding direkt (Index aus dem .Objects[] lesen).
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
LonghornUser
Beiträge: 796
|
Verfasst: Mo 24.04.06 14:24
Danke für die Antwort. Aber ich blick da noch nicht so ganz durch. Könnteste das noch etwas genauer erklären ? Hab sowas noch net so oft gemacht
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 24.04.06 15:05
Moin!
Aaalso:
Delphi-Quelltext 1: 2: 3: 4:
| GridView1.Cell[0,0].ObjectReference := TObject(3); MyImages.Draw(GridView1.Canvas,Rect.Left,Rect.Top,Integer(GridView1.Cell[0,0].ObjectReference)); |
So grob, halt; kommt auf deinen Code an, kann ich nicht genauer sagen.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Gausi
Beiträge: 8538
Erhaltene Danke: 475
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: Mo 24.04.06 15:12
An die einzelnen Bilder in einer ImageList kommt man z.B. so dran:
Delphi-Quelltext 1:
| MyImageList.GetBitmap(MyImageIndex,MyBitmap); |
_________________ We are, we were and will not be.
|
|
LonghornUser
Beiträge: 796
|
Verfasst: Mo 24.04.06 15:37
Und so ginge es nicht ?
Delphi-Quelltext 1: 2: 3: 4: 5:
| var G:TBitmap; begin G := TBitmap.Create; G := ImageList1.GetBitmap(0,G); gridview1.Cell[2,0].ObjectReference:=G; |
Da sagt er:
Quelltext 1:
| [Fehler] Unit1.pas(3041): Inkompatible Typen: 'TBitmap' und 'Boolean' |
Warum gehts denn net ?
|
|
Narses
Beiträge: 10182
Erhaltene Danke: 1255
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: Mo 24.04.06 15:53
Moin!
Gausi hat folgendes geschrieben: | An die einzelnen Bilder in einer ImageList kommt man z.B. so dran: |
Ja, schon klar.
Mein Ansatz geht aber in eine andere Richtung: statt die Referenzen auf die Images selbst nur die Nummer des Images der Zelle zuordnen. Erst beim Zeichnen der Zelle dann den Index in die ImageList auflösen in ein Bild.
Das ganze hat den Vorteil, dass du erstens keine weiteren Instanzen von TBitmap brauchst und durch Tauschen der ImageListen-Referenz gleich die ganzen Images in der Ansicht mit tauschen kannst (also z.B. eine größere Version gegen eine kleinere tauschen; vorausgesetzt, die Images sind alle an der gleichen Stelle in der Liste).
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Gausi
Beiträge: 8538
Erhaltene Danke: 475
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: Mo 24.04.06 16:02
So gehts:
Delphi-Quelltext 1: 2: 3: 4: 5:
| var G:TBitmap; begin G := TBitmap.Create; ImageList1.GetBitmap(0,G); gridview1.Cell[2,0].ObjectReference:=G; |
GetBitmap liefert nicht das Bild zurück, sondern ein Boolean Wert, obs halt geklappt hat oder nicht. Dass das Bild nach g reinkommt, dafür sorgt der Parameter g
_________________ We are, we were and will not be.
|
|