Load Picture from Database

edited 2:37AM in FastReport 4.0
Im trying to load a jpeg image stored in a oleobject field in an access database to a TfrxPictureView component. Ive searched the forums, but no-one seems to have an answer.

In my app, I can load an image component using the LoadfromStream method. First, i have to seek to the correct position in the stream before this works correctly.

So im assuming that using the frxpictureview components, i must load from a stream in the onbeforeprint method, but i cant seem to get it to work. Any help is appreciated.

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 2:37AM
    are you sure it is an oleobject field, and not a blobfield?
  • edited 2:37AM
    gordk wrote: »
    are you sure it is an oleobject field, and not a blobfield?

    Yes im sure. My current code in my app looks like:

    First - function to get the start position in the stream.

    function JpegStartsInBlob (PicField:TBlobField):integer;
    var
    bS : TADOBlobStream;
    buffer : Word;
    hx : string;
    begin
    Result := -1;
    bS := TADOBlobStream.Create(PicField, bmRead);
    try
    while (Result = -1) and (bS.Position + 1 < bS.Size) do
    begin
    bS.ReadBuffer(buffer, 1);
    hx:=IntToHex(buffer, 2);
    if hx = 'FF' then begin
    bS.ReadBuffer(buffer, 1);
    hx:=IntToHex(buffer, 2);
    if hx = 'D8' then Result := bS.Position - 2
    else if hx = 'FF' then bS.Position := bS.Position-1;
    end; //if
    end; //while
    finally
    bS.Free
    end; //try
    end;

    now the function to read the stream into a picture var.

    bS := TADOBlobStream.Create(ImageDataImage, bmRead);
    try
    bS.Seek(JpegStartsInBlob(ImageDataImage), soFromBeginning);
    Pic:=TJpegImage.Create;
    try
    Pic.LoadFromStream(bS);
    finally
    Pic.Free;
    end;
    finally
    bS.Free
    end;
  • edited 2:37AM
    Ok, so i managed to show the picture - the TfrxPictureView will load the picture directly from an OleObject field in the database. I had a picture placed on the incrrect band - which was why it wasnt showing up.

    So - if anyone else comes across this problem, simply select the OLEObject field and assign it to the TFrxPictureView Datafield.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.