Board index » delphi » Storing a JPEG image in a paradox BLOB field

Storing a JPEG image in a paradox BLOB field

Hello there,

I want to import a JPEG image into a BLOB field of a paradox table.
When I use the code:
"Table1Plaatje2.LoadFromFile(OpenPictureDialog1.FileName);" to import a BMP
image there is no problem, however when I select a JPEG image, Delphi
returns an error: "not a valid image" or something like that.
Can Anyone tell me why the BLOB field doesn't want JPEG images?

thanks, Chris

 

Re:Storing a JPEG image in a paradox BLOB field


Example:

var
  B: TBlobStream;
begin
  Table1.Edit;
  try
    B := Table1.CreateBlobStream(Table1.FieldByName('Image'), bmWrite);
    try
      Image1.Picture.SaveToStream(B);
    finally
      B.Free;
    end;
    Table1.Post;
  except
    Table1.Cancel;
    raise;
  end;
end;

ps. You can't use a TDBImage to display a Jpeg image. You have to use a
TImage and use the OnDataChange event to update the contents.

"Chris Stegeman" <CStege...@Deltion.nl> schreef in bericht
news:96ouhs$e6t$1@Snowflake_Obsidian.lion-access.net...

Quote
> Hello there,

> I want to import a JPEG image into a BLOB field of a paradox table.
> When I use the code:
> "Table1Plaatje2.LoadFromFile(OpenPictureDialog1.FileName);" to import a
BMP
> image there is no problem, however when I select a JPEG image, Delphi
> returns an error: "not a valid image" or something like that.
> Can Anyone tell me why the BLOB field doesn't want JPEG images?

> thanks, Chris

Re:Storing a JPEG image in a paradox BLOB field


Hi
And now how do you read the JPEG image from the table?
And does the procedure works the same for example GIF images?
Regards
JJ Loots

Re:Storing a JPEG image in a paradox BLOB field


Example:

uses
  Jpeg;

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
var
  B: TStream;
  J: TJpegImage;
begin
  // If record or field changed
  if not Assigned(Field) or (Field.FieldName = 'Image') then
  begin
    B := Table1.CreateBlobStream(Table1.FieldByName('Image'), bmRead);
    try
      J := TJpegImage.Create;
      try
        // Load image from the BLOB field
        J.LoadFromStream(B);
        Image1.Picture.Graphic := J;
      finally
        J.Free;
      end;
    finally
      B.Free;
    end;
  end;
end;

procedure TForm1.UpdateImage;
var
  B: TStream;
begin
  B := Table1.CreateBlobStream(Table1.FieldByName('Image'), bmWrite);
  try
    // Save image to BLOB field
    Image1.Picture.Graphic.SaveToStream(B);
  finally
    B.Free;
  end;
end;

"Koos Loots" <ko...@absa.co.za> schreef in bericht
news:3a9226fe$0$231@hades.is.co.za...

Quote
> Hi
> And now how do you read the JPEG image from the table?
> And does the procedure works the same for example GIF images?
> Regards
> JJ Loots

Other Threads