WebSnap应用,使用TBlobField方法存取图片时失败?????请教正确方法,谢谢!

解决方案 »

  1.   

    往数据库中存入图片和一段代码.<1175字节> aizb 
    procedure TForm1.DBGrid1DblClick(Sender: TObject);
    Var GraphField:TBlobField;
        BitMap:TBitMap;
        MemStream:TMemoryStream;
    begin
      if not DBGrid1.DataSource.DataSet.Active then
        Exit;
      if AnsiUpperCase(DBGrid1.Columns[DBGrid1.SelectedIndex].FieldName)='PIMAGE' then
      begin
        GraphField:=TGraphicField(DBGrid1.Columns[DBGrid1.SelectedIndex].Field);
        BitMap:=TBitMap.Create;
        try
          if OpenPictureDialog1.Execute then
          begin
            MemStream:=TMemoryStream.Create;
            try
              try
                BitMap.LoadFromFile(OpenPictureDialog1.FileName);
                BitMap.SaveToStream(MemStream);
              Except
                ShowMessage('文件格式错误!请选择BMP文件!');
                Raise;
              end;
              if (BitMap.Width<=32) or (BitMap.Height<=32) then
              begin
                GraphField.DataSet.Edit;
                GraphField.Clear;
                GraphField.LoadFromStream(MemStream);
                GraphField.DataSet.Post;
              end else
                ShowMessage('图片只能是小于32*32的BitMap文件!');
            finally
              MemStream.Free;
            end;
          end;
        finally
          BitMap.Free;
        end;
      end;
    end;
    参考一下吧!
      

  2.   

    TBlobField(WDM.adqPhoto.FieldByName('photo')).SaveToFile(FPhotoFile)