Autor Beitrag
DiamondDog
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Fr 30.05.08 16:30 
Hallo Leute,
leider bin ich noch Anfänger und daher bräucht ich etwas Hilfe.
Also ich würd gerne eine Combobox mit nem Bild füllen, welches aber alle X Pixel geschnitten werden muss. Hab dazu leider nichts passendes im Forum oder bei googel gefunden außer das:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
var
  Bitmap1, Bitmap2, Bitmap3, Bitmap4: TBitmap;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBox1.Style:=csOwnerDrawVariable;
  //Set height of one item
  ComboBox1.ItemHeight:=20;
  //load all bitmaps
  Bitmap1 := TBitmap.Create;
  Bitmap1.LoadFromFile('chem16.bmp');
  Bitmap2 := TBitmap.Create;
  Bitmap2.LoadFromFile('chip16.bmp');
  Bitmap3 := TBitmap.Create;
  Bitmap3.LoadFromFile('factry16.bmp');
  Bitmap4 := TBitmap.Create;
  Bitmap4.LoadFromFile('skylin16.bmp');
  //assign bitmaps with item objects - caption of the items: Bitmap 1 - Bitmap 4
  ComboBox1.Items.AddObject('Bitmap 1', Bitmap1);
  ComboBox1.Items.AddObject('Bitmap 2', Bitmap2);
  ComboBox1.Items.AddObject('Bitmap 3', Bitmap3);
  ComboBox1.Items.AddObject('Bitmap 4', Bitmap4);
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  Bitmap: TBitmap;
  Offset: Integer;
begin
  offset:=0;
  with ComboBox1.Canvas do
  begin
    FillRect(Rect);
    Bitmap := TBitmap(ComboBox1.Items.Objects[index]);
    if Bitmap <> nil then
    begin
      //copy bitmap to combobox coordinate
      BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
      Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
      Bitmap.Height), clred);
      Offset := Bitmap.width + 8;
    end;
    //Set a caption to each item
    TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index]);
  end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  //free all bitmap objects
  bitmap1.Free;
  bitmap2.Free;
  bitmap3.Free;
  bitmap4.Free;
end;
aber das ist ja nicht ganz das wass ich brauche.
Also die Combobox (Combobox2) soll mit einem png (angehängt) gefüllt werden wobei dann das erste Bild auf dem png = 1 ist und das 2te gleich 2 und so weiter.
Das Porblem ist das alle Bilder in der Combobox vom png untereinander sein sollen so wie bei dem Bild was ich angehängt habe (Combobox.jpg).
Das png befindet sich im Verzeichnis:
C:\Programme\Programm\Core\XStatuses\xstatuses_alpha.png
Die dll liegt im Verzeichniss:
C:\Programme\Programm\Plugins\beeper\beeper.dll
Die Combobox soll sich dann da das png weghollen.

Wäre super wenn mir da wer Helfen könnte.
Hab nämlich keine Ahnung wie ich das anstelle.

Ps:
Wenn das nicht der richtige Bereich ist. Bitte verschieben.
Einloggen, um Attachments anzusehen!
Nowo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 108



BeitragVerfasst: So 01.06.08 11:43 
Meinst du etwas so ?:
user defined image

Weis garnicht ob es da für Delphi eine Komponenten lösung gibt...
ich denke nicht das bei No-IP irgendein Draw befehl ausgeführt wird,
da die Bilder auch teilweise gifs sind.

_________________
Grüße Nowo
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: So 01.06.08 13:20 
Wie man das am besten anzeigt ist die eine Frage. Jedem Item ein Bild zuzuordnen, das geht in Delphi recht einfach. Benutze die Objects-Eigenschaft der Combobox. D.h. mit cbo.Item.AddObject jedem Eintrag einen Dateinamen zuordnen.

_________________
Gruß
Hansa
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 01.06.08 14:04 
Mit BitBlt kannst du einen bestimmten Bereich aus dem xstatuses_alpha.png kopieren und in ein TBitmap z.B. einfügen. Danach kannst du das Bitmap der Combobox wie hansa beschrieben hat zuweisen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: So 01.06.08 17:23 
@ GTA-Place
hast du vieleicht ein Beispiel dafür wie das genau funktioniert,
hab dazu nichts gefunden zumindest nichts was ich gebrauchen könnte.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 01.06.08 21:16 
ausblenden Delphi-Quelltext
1:
BitBlt(ZielImg.Canvas.Handle, 0, 0, Image1.Width, Image1.Height, Bitmap.Canvas.Handle, 0, 0, SRCCOPY);					


So würe man das Bild vom Bitmap ins ZielImg kopieren. Ich weiß aber gerade nicht - und es sieht nicht so aus - ob man da vom Quellenbild einen Bereich wählen kann.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: So 01.06.08 22:36 
hm...
also ich müste das schon so haben das ich die bestimmten Bereich dann vom Quellbild lade.
Ich möchte das ja extra so machen das das Quellbild auch getauscht werden kann.
Nowo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 108



BeitragVerfasst: So 01.06.08 23:53 
Mh wenn es eine Statische Liste wäre, an der sich also nichts mehr verändert,
könntest du einfach ein Langes(vertikal) Bild einfügen in dem die Smilys untereinander gezeigt werden.

_________________
Grüße Nowo
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mo 02.06.08 07:41 
Also die Liste bleibt so nur ahlt die Bilder sollen veränderbar sein.
Aber es muß schon aus dem png von oben sein.
Und das erste Bild von links soll dann wenn man es in der Combobox auswält den ItemIndex 1 haben.

Ps:
Könnte man nich irgendwie das Orginal bei Programmstart dann zerlegen speichern und dann verwenden? Wenn das bei jedem Start geschieht dann kann man das png ja auch ändern und beim start werden die Bilder dann mit den neuen überschrieben wenn es noch die alten sind wird zwar auch alles überschrieben aber das ist ja nicht schlimm.
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Di 03.06.08 09:57 
Hat den keiner eine Lösung es muß ja irgend wie zu lösen sein.
Wäre echt super wenn man das noch irgend wie knacken könnte,
weil dann wäre mein Plugin wo es rein muss fertig.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 03.06.08 13:57 
Hallo,

ich würde dafür eine ImageList verwenden.
Dessen Index kannst Du mit dem Index der ComboBox gleichsetzen und entsprechend in OnDrawItem das jeweilige Image zeichen.
ImageList.AddMasked splittet in einem Rutsch das lange Bild in einzelne 16 x 16 Pixel-Bilder auf und fügt sie in die ImageList ein.

Hab Deine png in bmp umgewandelt und in ein kleines Demo eingebaut.
Den Code als auch die kleine Echse findest Du im Anhang.
Einloggen, um Attachments anzusehen!
_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Di 03.06.08 15:04 
Hey super cool genau das was ich brauche nur geht das nur mit bmp oder geht das auch mit png?
Weil sonst müste ich das orginal bei jedem Programmstart laden und als bmp speichern lassen.
Es geht halt da drumm das ich an dem Orginal nix ändern kann außer vll das aussehn.
Aber das ist aufjedenfall schon mal ein Super Anfang.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 03.06.08 20:56 
Hallo,

warum als bmp speichern?
Hier in der EE findet man unter anderem das:[Delphi, Win32] Konvertierungsunit von BMP, JPG und PNG

Die dort zu findende Function LoadPNGFromFile liefert ein TBitMap zurück, das dann in eine ImageList eingelesen werden kann. Du brauchst also keine bmp-Datei zu speichern.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Di 03.06.08 22:31 
Ah ok muß ich mir dann mal zu gemüte führen.
Ein Problem hätte ich aber noch und zwar wenn mann deine exe so verwendet wie sie ist,
dann hat das erste Bild den Index = 0 es sollte aber 1 haben und vor dem ersten Bild ein x in fett als index 0.
So sollte das bildlich sein:
x
Bild 1
Bild 2
Bild 3
usw.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 03.06.08 22:45 
Hallo,

dann beleg doch den Index 0 der ImageList mit einem 16 x 16 Pixel-bmp mit einem X.
Das kannst Du bevor die png geladen wird in die ImageList setzen, denn mit AddMasked wird hinzugefügt, also dann ab Index 1.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Di 03.06.08 22:53 
Hey hab das jetzt so versucht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.FormCreate(Sender: TObject);
var z,x : Integer;
    bmp : TBitMap;
    bmp1 : TBitMap;
begin
  ComboBox1.Style := csOwnerDrawVariable;
  bmp := TBitMap.Create;
  bmp1 := TBitMap.Create;
  try
  bmp1.LoadFromFile(ExtractFilePath(ParamStr(0))+'x.bmp');
  bmp.LoadFromFile(ExtractFilePath(ParamStr(0))+'icons.bmp');
  x := bmp.Height;
  ComboBox1.ItemHeight := x + (2 * 2);
  for z := 2 to (bmp.Width div x)-1 do
    ComboBox1.Items.Add('');
  ImageList1.AddMasked(bmp,clNone);
  finally
    bmp.Free;
    bmp1.Free;
  end;
end;
aber da ist anscheinend noch nciht so ganz richtig.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 03.06.08 23:14 
Hallo,

verräts Du mir auch was nicht richtig ist. :wink:
Fehlt Dir das letzte Bild aus der Png?

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
DiamondDog Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 460



BeitragVerfasst: Mi 04.06.08 08:38 
Es Fehlen sogar die letzten 2 aber Fehlermeldungen bekomme ich keine.
Hab leider keine Ahnung wie ich das genau machen muss da ich ja wie oben schon gesagt noch Anfänger bin.

Edit:
Sorry hatte z := 2 muß aber z := 0 sein deswegen Fehlten die letzten beiden Bilder.
Aber wie ich das x an die 1erste Stelle bekomme hab ich immer noch nciht ganz verstanden.

Dann mit dem Converter hab das mal ausporbiert aber irgendwie bekomme ich da nur Fehlermeldungen. (Aber erst mal langsam weiter machen erst das Problem mit dem x lösen)


Zuletzt bearbeitet von DiamondDog am Mi 04.06.08 09:13, insgesamt 3-mal bearbeitet
passiv
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 270

WIN XP Professional
Delphi 7 Enterprise, Java (Eclipse), Python 2.5, Django 1.1
BeitragVerfasst: Mi 04.06.08 08:43 
so und jetzt erklärt mir mal wieso ihr ihm die ComboBoxEx verschweigt?
die wurde ja nicht mal erwähnt!! und nachdem es schon im Delphi (delphi 7 Enterprise, kA wie Personal da ausschaut) selbst eine Componente gibt die das selbst macht, wirds wohl auch im Internet eine entsprechende geben ...

_________________
Die Probleme, die es in der Welt gibt, sind nicht mit der gleichen Denkweise zu lösen, die sie erzeugt hat.
Albert Einstein
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 04.06.08 10:33 
Hallo,

@user profile iconpassiv
gut, ist auch eine Alternative, denke man könnte noch andere vorschlagen. :wink:
Aber auch da muss er die Images in eine ImageList reinbekommen.
Er braucht die Images dann nicht zu zeichen, sind aber eh nur 4 zeilen Code, siehe mein Demo.

@user profile iconDiamondDog
Das X bekommst Du an die erste Stelle in dem du das in bmp1 geladene Image zuerst in die ImageList einfügst.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
//...
ImageList1.AddMasked(bmp1,clNone);//<------    
ImageList1.AddMasked(bmp,clNone);  
//...

Dann noch ein zusätzliches Item zur ComboBox hinzufügen, sonst fehlt dir wieder am Ende eins.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )