我用了以下方法将jpg图片存入access数据库:
方法一:procedure Tform1.savepicture(img: Timage; ADOQ: TADOtable; field: string);
var photo: Tmemorystream;
begin
   photo := Tmemorystream.create;
   img.Picture.graphic.savetoStream(photo);
   Tblobfield(ADOQ.FieldByName(field)).loadfromstream(photo);
   photo.Clear;
end;方法二:image1.Picture.LoadFromFile(filename);
       fieldbyname('picture').assign(image1.picture);filename存的是图片存储路径,请帮助!我试了好久都不行!

解决方案 »

  1.   

    在access用OLE对象,在sql server里用image或binary存储流!存jpeg用image不能用dbimage
    uses jpeg,
    存 
    if not(query1.State in [dsEdit, dsInsert]) then exit;
    if OpenDialog1.Execute then
        begin
        (query1.FieldByName('img') as TBlobField).LoadFromFile(OpenDialog1.FileName);
         Image1.Picture.LoadFromFile(OpenDialog1.FileName);
         end;

    var
      JP: TJPEGImage;
      bs: TBlobStream;
    begin
      if not query1.FieldByName('img').IsNull then
      begin
        bs := TBlobStream.Create((query1.FieldByName('img') as TBlobField), bmRead);
        jp := TJPEGImage.Create;
        jp.LoadFromStream(bs);
        Image1.Picture.Assign(jp);
        bs.Free;
        jp.Free;
      end
      else
       Image1.Picture:=nil;
      

  2.   

    是不是access无法存储jpg格式图片阿!要先转换为bmp格式吧?不然怎么存不进去?
      

  3.   

    你的access要定义为ole字段类型
      

  4.   

    那当然知道了!是不是字段值都变成了大写表示存入了?怎么用上面的方法用image还是dbimage都无法显示出来啊?
      

  5.   

    学习。
    如果要保存的流中有控制字符则ADO在存取时将可能会出错:不能正确读取。
    我试过N次了。
      

  6.   

    不是那个意思了!比如我的picture字段为ole类型,如果为空时,显示“Blob”,如果已经存入图片了则为“BLOB”,而现在我已经显示为BLOB,但无法显示出来,用image控件根本没有反应,而用dbimage控件,则提示bitmap image is not valid,可是我存入的是jpg格式的图片阿!是不是存入的时候自动转换成二进制流形式就变成了bitmap形式?
      

  7.   

    dbimage不能表示jpg格式图片吧!
      

  8.   

    function JpgToPStr(filename:string)
    begin
      with TFileStream.Create(filename,fmOpenRead) do
      begin
        SetLength(Result,Size);
        Read(Point(Result)^,Size);
        Free;
      end;
    end;...
    ADOQuery1.FieldByName('Photo').AsString:=JpgToPStr(filename);
    ...
    Read用ADOBlobStream
      

  9.   

    我是要把数据库中的jpg图象显示出来,不是打开一个jpg文件!
      

  10.   

    var
    bs:TADOBlobStream;
    begin
    bs:=TADOBlobStream.Create(TBlobField(FieldByName('Photo')),bmRead);
    bs.SaveToFile('$Temp.jpg');
    Image1.Picture.LoadFromFile('$Temp.jpg');
    end;
      

  11.   

    提示savetofile为undeclared identifier,是不是要在前面申明什么?
      

  12.   

    procedure Tproc_frm.SpeedButton7Click(Sender: TObject);
    var
    j:tjpegimage;
    i:tbitmap;
    begin
     if OpenPictureDialog1.Execute then
     begin if uppercase(extractfileext(openpicturedialog1.FileName))='.JPG' then
            begin
            j:=tjpegimage.Create ;
            i:=tbitmap.Create ;
            j.LoadFromFile(openpicturedialog1.FileName );
            i.Assign(j)   ;
            i.SaveToFile(extractfilepath(application.exename)+'temp1.bmp');
            dbimage1.Picture.LoadFromFile(extractfilepath(application.exename)+'temp1.bmp');
            i.Free;
            j.Free;
            //showmessage('s');
            end
     else
     begin
     dbimage1.Picture.LoadFromFile(OpenPictureDialog1.Filename);
     end; end;
    end;
      

  13.   

    我是要把数据库中的jpg图象显示出来,不是打开一个jpg文件!