Board index » delphi » How can i store Jpeg image in DB

How can i store Jpeg image in DB

Hi,

After asking if TDBImage can handle jpeg file and it's seems not.
My question is how can i store jpeg image in DB using only delphi JPEG unit
??

Thanks for your answers at prr...@inter.net.il

Richard Grossman

 

Re:How can i store Jpeg image in DB


Here my answer to a sooner similar question:
For JPEGs and other binary data (except the standards) you must use TBlobField.
Assuming you've created one with the Title 'JPEG' you can try this code snippet:

procedure TForm1.Button1Click(Sender: TObject);
var
  JPEG: TJPEGImage;
  JPEGStream: TBlobStream;
begin
  if OpenPictureDialog1.Execute then
  begin
    JPEG := TJPEGImage.Create;
    try
      JPEG.LoadFromFile(OpenPictureDialog1.FileName);
      with Table1 do
      begin
        Edit;
        Append;  //or whatever
        if (FieldByName('JPEG') as TBlobField).IsBlob then
        begin
          JPEGStream :=
            TBlobStream.Create(TBlobField(Table1.FieldByName('JPEG')),
            bmWrite);
          try
            JPEG.SaveToStream(JPEGStream);
          finally
            JPEGStream.Free;
          end;
        end;
        Post;
      end;
    finally
      JPEG.Free;
    end;
  end;
end;

Toni

Quote
Richard Grossman wrote:

> Hi,

> After asking if TDBImage can handle jpeg file and it's seems not.
> My question is how can i store jpeg image in DB using only delphi JPEG unit
> ??

> Thanks for your answers at prr...@inter.net.il

> Richard Grossman

Other Threads