Bitmap image not valid

Signaler
-
Messages postés
199
Date d'inscription
samedi 15 novembre 2003
Statut
Membre
Dernière intervention
10 septembre 2020
-
Bonjour,
J'ai un problème avec le code qui a fonctionné mais je ne trouve pas l'erreur.

//////////////////////////////////////////////////////////////////////////////////////
unit Unit1;

interface

uses
{$IFDEF D6H}
  Variants,
{$ENDIF}
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, DB, Jpeg,
  ExtDlgs, ADODB;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    DBImage1: TDBImage;
    Button1: TButton;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    ADOTable1Ref: TWideStringField;
    ADOTable1desig: TWideStringField;
    ADOTable1n_typ: TIntegerField;
    ADOTable1marq: TWideStringField;
    ADOTable1prix: TBCDField;
    ADOTable1imge: TBlobField;
    DataSource1: TDataSource;
    OpenPictureDialog1: TOpenPictureDialog;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Button2: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure ADOTable1AfterScroll(DataSet: TDataSet);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ADOTable1AfterScroll(DataSet: TDataSet);
var
  JpegImage: TJPEGImage;
  BlobStream: TStream;
begin
  if (not ADOTable1.FieldByName('imge').IsNull) then
    begin
      BlobStream := ADOTable1.CreateBlobStream(ADOTable1.FieldByName('imge'),bmRead);
      JpegImage := TJPEGImage.Create;
      try
        JpegImage.LoadFromStream(BlobStream);
        image1.Picture.Assign(JpegImage);
        image1.Visible := True;
      finally
        JpegImage.Free;
        BlobStream.Free;
      end;
    end
  else
    image1.Visible := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
  if (OpenDialog1.Execute) then
   begin
     ADOTable1.Edit;
     try
       BlobStream := ADOTable1.CreateBlobStream(ADOTable1.FieldByName('imge'),bmWrite);
       FileStream := TFileStream.Create(OpenDialog1.FileName,fmOpenRead or fmShareDenyNone);
       BlobStream.CopyFrom(FileStream,FileStream.Size);
       FileStream.Free;
       BlobStream.Free;
       ADOTable1.Post;
       ADOTable1AfterScroll(ADOTable1);
     except
       ADOTable1.Cancel;
     end;
   end;
End;


procedure TForm1.Button2Click(Sender: TObject);
var
  FileStream: TFileStream;
  BlobStream: TStream;
begin
  if (SaveDialog1.Execute) then
    begin
      FileStream := TFileStream.Create(SaveDialog1.FileName,fmCreate);
      BlobStream := ADOTable1.CreateBlobStream(ADOTable1.FieldByName('imge'),bmRead);
      FileStream.CopyFrom(BlobStream,BlobStream.Size-BlobStream.Position);
      BlobStream.Free;
      FileStream.Free;
    end;
end;

end.

///////////////////////////////////////////
J'espère que quelqu'un a une idée.
Merci beaucoup

1 réponse

Messages postés
199
Date d'inscription
samedi 15 novembre 2003
Statut
Membre
Dernière intervention
10 septembre 2020
7
salut
regarde https://codes-sources.commentcamarche.net/forum/affich-10083657-inserer-une-image-jpeg-dans-bde#p10096382

en changeant dbimage1 par image1 ??
maintenant dans quelle procédure as-tu l'erreur ?