Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: 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:
ausblenden 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: 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 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: 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
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 24.04.06 15:05 
Moin!

Aaalso: ;)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
GridView1.Cell[0,0].ObjectReference := TObject(3); // Diese Zelle soll Bild Nr. 4 zugeordnet bekommen

// in OnDrawCell dann später (ich unterstelle, deine ImageList heißt MyImages):
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
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 24.04.06 15:12 
An die einzelnen Bilder in einer ImageList kommt man z.B. so dran:

ausblenden Delphi-Quelltext
1:
MyImageList.GetBitmap(MyImageIndex,MyBitmap);					

_________________
We are, we were and will not be.
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Mo 24.04.06 15:37 
Und so ginge es nicht ?
ausblenden 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:
ausblenden Quelltext
1:
[Fehler] Unit1.pas(3041): Inkompatible Typen: 'TBitmap' und 'Boolean'					

Warum gehts denn net ?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 24.04.06 15:53 
Moin!

user profile iconGausi 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). :D

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 24.04.06 16:02 
So gehts:
ausblenden 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.