在Delphi中,我想将一个jpg图像从数据库中取出并显示,在不想通过临时文件的方法,请高手指点。(注意条件: 1.JPG图像 2.不使用临时文件)
    多谢!!!

解决方案 »

  1.   

    关于此主题请参考:
        《表》数据库与图片(文件)的关系如何处理?
        http://access911.net/index.asp?u1=a&u2=71FAB51E16DC
      

  2.   

    你这个是 DELPHI 控件使用的问题,请去 DELPHI 板块询问
      

  3.   

    var
      tmpPicStream: TAdoBlobStream;
      MS: TMemoryStream;
      Pic : TJpegImage;
    ----------------------------------------------------------------------
        tmpPicStream:= TAdoBlobStream.Create(TBlobField(ADOQuery1.FieldByName('Pic')),bmRead);
        try
            tmpPicStream.Position := 0;
            tmpPicStream.SaveToStream(MS);
            MS.Position := 0;
            Pic := TJpegImage.Create;       //只能针对特定类型的图像进行显示, 比如JPG BMP等,而无法支持其他格式的图片
            Pic.LoadFromStream(MS);
            Image1.Picture.Graphic := Pic;
         finally
              tmpPicStream.Free;
          end;
      

  4.   

    上面是用的Image控件显示JPG图片.
        我想知道另外一种情况:各种多媒体资料(各类图片,影音资料)以二进制保存在数据库中,怎么样用Ole对象显示而不使用临时文件? 
        我直接用Ole对象LoadFromStream总是出错,后来只好使用先把Stream SaveToFile,然后Ole CreateObjectFromFile 来解决了.
      

  5.   

    感谢大家的帮助,尤其是 xinfeng109(辛风) ,问题已解决,以下是本人编的代码供大家参考。function LoadGraphicFromStream(const SM: TStream; Ext: string): TGraphic;
    type
      TFileFormat = record
        GraphicClass: TGraphicClass;
        Extension: string;
      end;
    const
      SupportFmt: array[0..5] of TFileFormat = (
                                    (GraphicClass: TBitMap;     Extension: 'BMP'),
                                    (GraphicClass: TJPEGImage;  Extension: 'JPG'),
                                    (GraphicClass: TJPEGImage;  Extension: 'JPEG'),
                                    (GraphicClass: TIcon;       Extension: 'ICO'),
                                    (GraphicClass: TMetaFile;   Extension: 'WMF'),
                                    (GraphicClass: TMetaFile;   Extension: 'EMF')
                                    );
    var
      I: Integer;
      GC: TGraphicClass;begin
      Result := nil;
      GC := nil;
      Ext := AnsiUpperCase(Ext);
      for I := 0 to High(SupportFmt) do
        with SupportFmt[I] do
          if Extension = Ext then begin
            GC := GraphicClass;
            Break;
          end;
      if GC = nil then Exit;  Result := GC.Create;
      try
        SM.Position := 0;         // *** 错误在此,原来没加这句,犯了一个低级错误
        Result.LoadFromStream(SM);
      except
        Result.Free;
        raise;
      end;
    end;procedure TfrmDesign.FormCreate(Sender: TObject);
    var
      SM: TMemoryStream;
      Ext: string; // 扩展名
    begin
      Ext := tab.FieldByName('Ext').AsString;
      SM := TMemoryStream.Create;
      TBlobField(tab.FieldByName('Img')).SaveToStream(SM);
      img.Picture.Graphic := LoadGraphicFromStream(SM, Ext);
      SM.Free;
    end;