[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

dbimage drawing

I thought if I could use an Image component to draw in, I would be able to do the same with a DBImage to save the drawing in a graphic field in a paradox table.

I have not been able to figure out how to save and retrieve the drawings.

I can I use a DBImage to not ony draw in, but save it and retrieve it from a table?

I am using the code below to draw in the DBimage:

procedure TForm1.FormCreate(Sender: TObject);
var bmp: TBitmap;
begin
  bmp := TBitmap.Create;
  bmp.Width := DBImage1.Width;
  bmp.Height := DBImage1.Height;
  bmp.PixelFormat := pf24bit;
  DBImage1.Picture.Bitmap.Assign(bmp);
  bmp.Free;
end;

procedure TForm1.DBImage1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
    if ssLeft in Shift then
    begin
    DBImage1.Picture.Bitmap.Canvas.MoveTo(xp,yp);
    DBImage1.Picture.Bitmap.Canvas.LineTo(X,Y);
    xp := X;
    yp := y;
    end;
end;

procedure TForm1.DBImage1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  xp := X;
  yp := y;
end;
0
aharasts
Asked:
aharasts
1 Solution
 
TheRealLokiSenior DeveloperCommented:
Wrote this for you, hope it helps
I am using the biolife tables from the bde install as a demo
but the functionality should work ok
the x,y drawing needs some tweaking to match the mousr position...
You need to cliock on edit (navigator button) before you can draw
then you need to hit post to save it or cancel


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DBCtrls, Db, DBTables, DBCGrids, ComCtrls, ExtCtrls, Buttons, (*GifImage, *)Jpeg;

type
  TForm1 = class(TForm)
    tbmastertable: TTable;
    tbbiolife: TTable;
    dsMaster: TDataSource;
    tbmastertableSpeciesNo: TFloatField;
    tbbiolifeSpeciesNo: TFloatField;
    tbbiolifeCategory: TStringField;
    tbbiolifeCommon_Name: TStringField;
    tbbiolifeSpeciesName: TStringField;
    tbbiolifeLengthcm: TFloatField;
    tbbiolifeLength_In: TFloatField;
    tbbiolifeNotes: TMemoField;
    tbbiolifeGraphic: TGraphicField;
    DBNavigator1: TDBNavigator;
    DBImage1: TDBImage;
    dsbiolife: TDataSource;
    ColorDialog1: TColorDialog;
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure DBImage1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure DBImage1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure DBImage1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
      pendown: boolean;
      pencolor: TColor;
  end;

var
  Form1: TForm1;

IMPLEMENTATION

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
    begin
        tbmastertable.databasename := ExtractFilePath(paramstr(0));
        tbbiolife.databasename := ExtractFilePath(paramstr(0));
        tbbiolife.Open;
        tbmastertable.Open;
    end;

procedure TForm1.FormDestroy(Sender: TObject);
    begin
        tbbiolife.Close;
        tbmastertable.Close;
    end;

procedure TForm1.DBImage1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        if tbbiolife.State in dsEditModes then
        begin
            pendown := true;
            DBImage1.Picture.Bitmap.Canvas.Pen.Color := pencolor;

            DBImage1.Picture.Bitmap.Canvas.MoveTo(X, Y);
        end;
    end;

procedure TForm1.DBImage1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    begin
        if (tbbiolife.State in dsEditModes) and pendown then
          DBImage1.Picture.Bitmap.Canvas.LineTo(X, Y);
    end;

procedure TForm1.DBImage1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
        if tbbiolife.State in dsEditModes then
          pendown := false;
    end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
    begin
        if ColorDialog1.Execute then
          pencolor := ColorDialog1.Color;
    end;


end.



**********  FORM  ************

object Form1: TForm1
  Left = 331
  Top = 153
  Width = 443
  Height = 356
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDestroy = FormDestroy
  PixelsPerInch = 96
  TextHeight = 13
  object SpeedButton1: TSpeedButton
    Left = 392
    Top = 48
    Width = 23
    Height = 22
    Glyph.Data = {
      5A010000424D5A01000000000000760000002800000013000000130000000100
      040000000000E400000000000000000000001000000000000000000000000000
      8000008000000080800080000000800080008080000080808000C0C0C0000000
      FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00F77777777777
      777777700000FAAAAA0EEEEE0DDDDD700000FAAAAA0EEEEE0DDDDD700000FAAA
      AA0EEEEE0DDDDD700000FAAAAA0EEEEE0DDDDD700000FAAAAA0EEEEE0DDDDD70
      0000F00000000000000000700000F777770FFFFF000000700000F777770FFFFF
      000000700000F777770FFFFF000000700000F777770FFFFF000000700000F777
      770FFFFF000000700000F00000000000000000700000F999990BBBBB0CCCCC70
      0000F999990BBBBB0CCCCC700000F999990BBBBB0CCCCC700000F999990BBBBB
      0CCCCC700000F999990BBBBB0CCCCC700000FFFFFFFFFFFFFFFFFFF00000}
    OnClick = SpeedButton1Click
  end
  object Label1: TLabel
    Left = 168
    Top = 32
    Width = 135
    Height = 13
    Caption = 'you must click "edit" to draw'
  end
  object DBNavigator1: TDBNavigator
    Left = 96
    Top = 0
    Width = 240
    Height = 25
    DataSource = dsbiolife
    TabOrder = 0
  end
  object DBImage1: TDBImage
    Left = 96
    Top = 48
    Width = 289
    Height = 225
    DataField = 'Graphic'
    DataSource = dsbiolife
    TabOrder = 1
    OnMouseDown = DBImage1MouseDown
    OnMouseMove = DBImage1MouseMove
    OnMouseUp = DBImage1MouseUp
  end
  object tbmastertable: TTable
    DatabaseName = 'C:\test\DBCtrlGrid loads pictures\'
    TableName = 'mastertable.db'
    Left = 24
    Top = 28
    object tbmastertableSpeciesNo: TFloatField
      FieldName = 'Species No'
    end
  end
  object tbbiolife: TTable
    DatabaseName = 'C:\test\DBCtrlGrid loads pictures\'
    IndexFieldNames = 'Species No'
    TableName = 'biolife.db'
    Left = 24
    Top = 92
    object tbbiolifeSpeciesNo: TFloatField
      FieldName = 'Species No'
    end
    object tbbiolifeCategory: TStringField
      FieldName = 'Category'
      Size = 15
    end
    object tbbiolifeCommon_Name: TStringField
      FieldName = 'Common_Name'
      Size = 30
    end
    object tbbiolifeSpeciesName: TStringField
      FieldName = 'Species Name'
      Size = 40
    end
    object tbbiolifeLengthcm: TFloatField
      FieldName = 'Length (cm)'
    end
    object tbbiolifeLength_In: TFloatField
      FieldName = 'Length_In'
    end
    object tbbiolifeNotes: TMemoField
      FieldName = 'Notes'
      BlobType = ftMemo
      Size = 50
    end
    object tbbiolifeGraphic: TGraphicField
      FieldName = 'Graphic'
      BlobType = ftGraphic
    end
  end
  object dsMaster: TDataSource
    DataSet = tbmastertable
    Left = 32
    Top = 64
  end
  object dsbiolife: TDataSource
    DataSet = tbbiolife
    Left = 48
    Top = 88
  end
  object ColorDialog1: TColorDialog
    Ctl3D = True
    Left = 392
    Top = 80
  end
end
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now