У грида есть событие OnDrawColumnCell в нем и рисуй.
| Код | procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var bmp: TBitmap; BlobStream: TBlobStream; begin if Column.Field.IsBlob{ and (DataCol = N) (*Если есть неграфические blob поля*)}then begin bmp := TBitmap.Create; //Можно содать один раз в FormCreate BlobStream := TBlobStream.Create(Column.Field as TBlobField, bmRead); if GetBitmap(BlobStream, bmp) then (Sender as TDBGrid).Canvas.StretchDraw(Rect, bmp) else (Sender as TDBGrid).Canvas.FillRect(Rect); bmp.Free; //И соответственно уничтожить в FormDestroy BlobStream.Free; end; end;
|
GetBitmap
| Код | function GetBitmap(BlobStream: TStream; Bitmap: TBitmap): Boolean; var BitmapStream: TMemoryStream; BlobStreamInterface, BitmapStreamInterface: IStream; GPImage: TGPImage;//unit GDIPOBJ.pas gbmp: TGUID; v: int64; begin result := False; if not Assigned(Bitmap) or not(Bitmap is TBitmap) then Exit; BlobStreamInterface := TStreamAdapter.Create(BlobStream); BlobStreamInterface.Seek(0, 0, v); GPImage := TGPImage.Create(BlobStreamInterface); BitmapStream := TMemoryStream.Create; if Ok = GPImage.GetLastStatus then begin BitmapStream := TMemoryStream.Create; BitmapStreamInterface := TStreamAdapter.Create(BitmapStream); GetEncoderClsid('image/bmp', gbmp); //unit GDIPUTIL.pas GPImage.Save(BitmapStreamInterface, gbmp); BitmapStreamInterface.Seek(0, 0, v); Bitmap.LoadFromStream(BitmapStream); BitmapStream.Free; BitmapStreamInterface := nil; Result := True; end else begin Bitmap.Canvas.Brush.Color := 0; Bitmap.Canvas.FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height)); end; BlobStreamInterface := nil; GPImage.Free; end;
|
|