怎么在DELPHI中将图片存入到SQLSERVER中????并且怎么样存到MYSQL与ACCESS中呢用图片存入还是存路径呢?
我用PHP+MYSQL时只是存储路径然后调用,DELPHI中用什么存取呢?
望能详细解答!
thank you very much!

解决方案 »

  1.   

    sqlserver中有一image類型.做一字段為image類型.然後就可調圖片文件到這個字段了.(bmp文件).
      

  2.   

    好做,给你一个例子
    var
      jpeg: TJPEGIMAGE;
      s: string;
    begin
      if Image2.Tag = 0 then
      begin
        showmessage('dd');
        exit;
      end;
      s := extractfilepath(Application.ExeName) + 'jpeg.jpg';
      jpeg := TJPEGIMAGE.Create;
      jpeg.Assign(Image2.picture);
      jpeg.CompressionQuality := 75;
      jpeg.Compress;
      jpeg.SaveToFile(s);
      if DM.DS_YGPHOTO.Active then
      begin
        if form1.Image1.Tag = 0 then
        begin
          DM.DS_YGPHOTO.Insert;
          DM.DS_YGPHOTO.fieldbyname('bh').AsString := DM.DS_YGHMC.fieldbyname('bh').AsString;
          tblobfield(DM.DS_YGPHOTO.fieldbyname('photo')).LoadFromFile(s);
        end;
        if form1.Image1.Tag = 1 then
        begin
          DM.DS_YGPHOTO.edit;
          tblobfield(DM.DS_YGPHOTO.fieldbyname('photo')).LoadFromFile(s);
        end;    DM.DS_YGPHOTO.Post;
      end;
      freeandnil(jpeg);
    上面的是存储
    读取
    var
      jpeg: TJPEGIMAGE;
      stream: TMemoryStream;
    begin
      Image1.picture.Assign(nil);
      if DM.DS_YGPHOTO.fieldbyname('photo').IsNull then
      begin
        Image1.Tag := 0;
        Panel2.Caption := '无照片';
      end
      else
      begin
        jpeg := TJPEGIMAGE.Create;
        stream := TMemoryStream.Create;
        tblobfield(DM.DS_YGPHOTO.fieldbyname('photo')).savetostream(stream);
        stream.Seek(0, soFromBeginning);
        jpeg.loadfromstream(stream);
        Image1.picture.Bitmap.Assign(jpeg);
        freeandnil(jpeg);
        freeandnil(stream);
        Image1.Tag := 1;
      end;
      

  3.   

    我的是存取JPEG格式的,如果BMP的话,就直接做就可以了,不用那个JPEG单元了
      

  4.   

    数据库中用IMAGE类型。
    存取时定义一个TBLOBFIELD变量。具体用法看看帮助/
      

  5.   

    // 没啥说的
    procedure TRyglForm.photo_Save(S: TMemoryStream);
    type
      TByteArray = array[0..MaxInt - 1] of byte;
      PByteArray = ^TByteArray;
    var
      C: TStrings;
    begin
      C := TStringList.Create;
      try
        C.Add('DECLARE @v_ry INT;');
        C.Add(Format('SET @v_ry=%d;', [FHmc.ryid]));
        C.Add('DECLARE @v_rq INT;');
        C.Add(Format('SET @v_rq=%d;', [GetYMD]));
        C.Add('UPDATE photo SET bh=bh+1 WHERE ry=@v_ry;');
        C.Add('INSERT INTO photo (ry, bh, rq, zp) VALUES (@v_ry, 0, @v_rq, 0xFF);');
        C.Add('EXEC sp_dboption ''wage'', ''select into/bulkcopy'', ''true'';');
        C.Add('DECLARE @v_zp binary(16);');
        C.Add('SELECT @v_zp=TEXTPTR(zp) FROM photo WHERE ry=@v_ry AND bh=0;');
        mis.Zlb.CompressMemoryStream(S);
        C.Add(Format('WRITETEXT photo.zp @v_zp WITH LOG 0x%s;', [mis.MemoryToHex(S)]));
        C.Add('EXEC sp_dboption ''wage'', ''select into/bulkcopy'', ''false''');
        ExecVar(C, true, true);
      except
        FreeAndNil(C);
      end;
    end;
      

  6.   

    我写了一段存储图片的相关程序如下可是老提示错误
    //[Warning] Unit1.pas(44): Constructing instance of 'TGraphic'     containing abstract method 'TGraphic.LoadFromStream'
    //[Warning] Unit1.pas(44): Constructing instance of 'TGraphic' containing abstract method 'TGraphic.SaveToStream'
    //[Warning] Unit1.pas(44): Constructing instance of 'TGraphic' containing abstract method 'TGraphic.LoadFromClipboardFormat'
    //[Warning] Unit1.pas(44): Constructing instance of 'TGraphic' containing abstract method 'TGraphic.SaveToClipboardFormat'
    并且不能运行请高手详细解答!!!!!!!!unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, DBTables, StdCtrls, ExtCtrls, Mask, DBCtrls,JPEG;type
      TForm1 = class(TForm)
        Image1: TImage;
        Button1: TButton;
        Table1: TTable;
        DataSource1: TDataSource;
        OpenDialog1: TOpenDialog;
        Edit1: TEdit;
        Button2: TButton;
        Edit2: TEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
        opendialog1.Execute;
        image1.Picture.LoadFromFile(opendialog1.FileName);
    end;procedure TForm1.Button2Click(Sender: TObject);
     var graphic1:TGraphic;
         
    begin
          graphic1:=TGraphic.Create;
          graphic1.LoadFromFile(opendialog1.FileName);
          table1.Insert;
          table1.FieldByName('id').AsInteger:=3;
          table1.FieldByName('name').AsString:=edit2.Text;
          table1.fields[16].Assign(graphic1.Create);
          table1.Post;
          graphic1.Free;end;end.
      

  7.   

    table1.fields[16].Assign(graphic1.Create);这是什么用意?