我在数据库中建了一个表专门来保存图片,我要把图片显示在combobox中
怎么实现呢?谢谢各位大侠小侠!

解决方案 »

  1.   

    >>我要把图片显示在combobox中
    比較麻煩, 我不明白你為什麼要這麼做, 
    你的問題應該分成:
    1,將數據庫的保存圖片取出
    2, 顯示到 combobox 中將 combobox 的style 設為 csOwnerDrawFixed
    之類的,自己在上面畫了!
      

  2.   

    TO  aiirii(ari-爱的眼睛)首先我很感谢你回我问题的回答
    第一个问题我可以通过流传输来解决,
    关键是第二个我把图片后对combobox画上去的问题,我看了一些资料,他们是通过取IMAGELIST的
    图片来画上去的,跟我的取出来的有点区别,
    我给大家帖一段伴水的代码;
    希望那为高手帮我改改看,我刚学DELPHI不久,对画布这玩意不是很了解,谢谢!
    將 combobox 的style 設為 csOwnerDrawFixedprocedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    var
      Bitmap: TBitmap;
      Offset: Integer;
    begin
      Bitmap := TBitmap.Create;
      with TComboBox(Control).Canvas do try
        FillRect(Rect);
        Offset := 2;
        ImageList1.GetBitmap(Index, Bitmap);
        BrushCopy(Bounds(Rect.Left + Offset, Rect.Top, Bitmap.Width, Bitmap.Height),
          Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clRed);
          Offset := Bitmap.width + 6;
        TextOut(Rect.Left + Offset, Rect.Top, TComboBox(Control).Items[Index]);
      finally
        Bitmap.Free;
      end;
    end;
      

  3.   

    有类似的控件,可以参考一下,比如:1stClass
      

  4.   

    我昨天看刘艺的《Delphi 面向对象研究》,里面有个这样的例子楼主的在 DrawItem 事件里面重画的方法可以的
      

  5.   

    我也想早点解决呀,如果实在没有办法,只能用comboboxen了,虽然不太理想!不过还是感谢各位的回答
      

  6.   

    楼上不是有人说了吗,刘艺的<<Delphi面向对象的编程>>
    里面有
    在网上找找源码就是了
      

  7.   

    TO searoom(海龙) ,首先谢谢你的回答,画上去当然可以,但是我取出来的是个流,当然也可以转化为图片先,有什么办法把图片画进COMBOBOX?如果可以的话,如果我是多个图片的时候,怎么解决排列问题,会不会代替前面刚画的?希望大家再顶顶
      

  8.   

    var Form1: TForm1; MyBitmap1, MyBitmap2, MyBitmap3, MyBitmap4: TBitmap; 
      implementation 
      {$R *.DFM} 
      procedure TForm1.FormCreate(Sender: TObject); 
      begin 
       MyBitmap1 := TBitmap.Create; 
       MyBitmap1.LoadFromFile(`e:\chemical.bmp’); 
       MyBitmap2 := TBitmap.Create; 
       MyBitmap2.LoadFromFile(`e:\arrow1l.bmp’); 
      MyBitmap3 := TBitmap.Create; 
       MyBitmap3.LoadFromFile(`e:\arrow1dl.bmp’); 
       MyBitmap4 := TBitmap.Create; 
       MyBitmap4.LoadFromFile(`e:\arrow1dr.bmp’); 
       ComboBox1.Items.AddObject(`Bitmap1’, MyBitmap1); 
       ComboBox1.Items.AddObject(`Bitmap2’, MyBitmap2); 
       ComboBox1.Items.AddObject(`Bitmap3’, MyBitmap3); 
       ComboBox1.Items.AddObject(`Bitmap4’, MyBitmap4); 
       ListBox1.Items.AddObject(`Bitmap1’, MyBitmap1); 
       ListBox1.Items.AddObject(`Bitmap2’, MyBitmap2); 
       ListBox1.Items.AddObject(`Bitmap3’, MyBitmap3); 
       ListBox1.Items.AddObject(`Bitmap4’, MyBitmap4); 
      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{适当的空档使图片关系分明,clred为透明色} 
       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; {图片与文字的间隔,以组件的Left属性计算} 
       end; 
       TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index]); {显示文字} 
      end; 
      end; 
      

  9.   

    procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); 
      var Bitmap: TBitmap; Offset: Integer; 
      begin 
       offset:=0; 
       with ListBox1.Canvas do 
       begin 
       FillRect(Rect); 
       Bitmap := TBitmap(ListBox1.Items.Objects[Index]); 
       if Bitmap <> nil then{粘贴图片} 
       begin 
       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; {图片与文字的间隔,以组件的Left属性计算} 
       end; 
       TextOut(Rect.Left + Offset, Rect.Top, Listbox1.Items[Index]); {显示文字} 
       end; 
      end; 
      end.   图片取得可以用流抓取,  以上只供参考,呵呵
      

  10.   

    非常感谢 along19811006(努力,在努力) ,问题解决,代码:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        procedure FormCreate(Sender: TObject);
        procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
          Rect: TRect; State: TOwnerDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
       Mybitmap1,Mybitmap2 :TBitmap;
    implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
        MyBitmap1 := TBitmap.Create;
        mybitmap1.LoadFromFile('d:\1.bmp');
        MyBitmap2 := TBitmap.Create;
        MyBitmap2.LoadFromFile('d:\2.bmp');
        ComboBox1.Items.AddObject('Bitmap1', MyBitmap1);
        ComboBox1.Items.AddObject('Bitmap2', MyBitmap2);
    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
       BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width,
       Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
       Bitmap.Height), clred);
       Offset := Bitmap.width + 2; 
       end;
      // TextOut(Rect.Left + Offset, Rect.Top, Combobox1.Items[Index]); 
      end;
    end;end.