Board index » delphi » JPEG error #51 - Trying to store a JPEG in a Interbase BLOB field

JPEG error #51 - Trying to store a JPEG in a Interbase BLOB field

Hi,

How can I store a JPEG image in a Interbase 6.0 BLOB field ?

TIA,

Mrcio Barroso

 

Re:JPEG error #51 - Trying to store a JPEG in a Interbase BLOB field


I'm New To Delphi Myself, but I managed to cobble something together
temporarily; You have to add JPEG to the uses clause. Good luck, I hope
this helps.

//This Procedure Inserts A Picture And An Identifying ID field
Procedure TForm1.insertPic(id: Integer;FileName: WideString);
 var
  BlobField: TField;
  IDField: TField;
  BS: TStream;
  MyPIC: TJPEGImage;
  fn:WideString;
begin

MyPIC := TJPEGImage.Create;
  MyPIC.LoadFromFile(FileName);
  with Table1 do
  begin
    Insert;
    BlobField := FieldByName('IMAGE');
     IDField := FieldByName('REC_ID');
     IDField.Value :=id;
    BS := CreateBlobStream(BlobField,bmWrite);
    MyPIC.SavetoStream(BS);
    Post;
  end;

end;

////////////////////////////////////
//This Reads A JPEG from the table, saves it to a temp file and loads it
//back into a TImage control. There has got to be a better way to do
//this i'm sure.

Procedure TForm1.ReadPic();
 var
  BlobField: TField;
  IDField: TField;
  BS: TStream;
  MyPIC: TJPEGImage;
  fn:WideString;
begin

MyPIC := TJPEGImage.Create;
  with Table1 do
  begin
    BlobField := FieldByName('IMAGE');
    BS := CreateBlobStream(BlobField,bmRead);
    MyPIC.LoadFromStream(BS);
    MyPic.SaveToFile('C:\TEMP\TMP.jpg');
    Image1.Picture.LoadFromFile('C:\TEMP\TMP.jpg');
  end;

end;

Other Threads