load image from blob field in TTMSFNCTableViewItem.bitmap

Hi

how to load image from blob field in TTMSFNCTableViewItem.bitmap ?

i tried

    Try
      S := TBytesStream.Create(xdatawebDataSet.FieldByName('Immagine').AsBytes);
      TableViewItem.Bitmap.LoadFromStream(S);
    Finally
      S.Free;
    End;

but nothing

@Pieter_Scheldeman

i used

    If DataSet.FieldByName('Immagine').AsString <> '' Then
      Bitmap.URL := 'data:image/jpeg;base64,'+DataSet.FieldByName('Immagine').AsString;

where Immagine is a Blob field and on QueryString:='$expand=Immagine'

i've error :

DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.

Immagine have origin from a Firebird DB blob type 0 field (binary)

from this error, the logical conclusion would be that your dataset field value is not base64 encoded.

My situation is this :

  1. On firebird database i created a field IMMAGINE BLOB SUB_TYPE 0 SEGMENT SIZE 80,
  2. from a client windows application i load an image with this :
    TBlobField(DM0.dstSettArt.FieldByName('Immagine')).LoadFromFile(ImgFileName);

NOTE : field is BLOB binary

  1. entity of this field is

    [Column('IMMAGINE', [TColumnProp.Lazy])]
    FIMMAGINE: TBlob;

  2. i my web app i'm trying to load this image with :

    // from webappcoreblob sample
    imgMain.Url:=DM0.conDB.URL + '/' +
       String(TJSObject(DM0.wdSett.CurrentData)['Immagine@xdata.proxy']);
   OR
    imgMain.URL:='data:image/jpeg;base64,'+DM0.wdSett.FieldByName('Immagine').AsString;

BUT nothing always error

Attached my sample application (is RAR archive) that you can modify (if you can) to load this image on frmMain.btMenuOrdClick(Sender: TObject);

Help me please. Thx

Ristord.zip (799.9 KB)

hi , discard previous Ristord.zip. Use this please (Archive is RAR type)

Ristord.zip (802.8 KB)

What you do cannot work. You store the image in binary format and then try to retrieve it as string.
Either encode it in the DB as base64 string and use it as-is client-side or retrieve the DB field data as binary data and convert it client side to base64 string.

But can i add to my entity class a new "calculated" field with Image_Base64 with get_ and set_ values and use it to webapp ? if yes can give me code sample ?

I have no idea what you are actually using when you say: "can i add to my entity class"

Ok nothing ...

Go to original problem :

Why this go fine to load an image WebImageControl1.URL:='data:image/jpeg;base64,'+DataSet.FieldByName('Immagine').AsString;

BUT with instruction below give me an error ?
TMSFNCTableViewItem.Bitmap.URL:='data:image/jpeg;base64,'+DataSet.FieldByName('Immagine').AsString;

Error loading image data:image/jpeg;base64,Lw¥\no\n ...etc..
There is another way to load a base64 image string into TMSFNCTableViewItem.Bitmap?

You need to use TMSFNCTableViewItem.Bitmap.LoadFromResource

I already tried it dont goooo. see this please :

If DataSet.FieldByName('Immagine').AsString <> '' Then Begin
        WebImageControl1.URL:='data:image/jpeg;base64,'+DataSet.FieldByName('Immagine').AsString;
        Bitmap.LoadFromResource('data:image/jpeg;base64,'+DataSet.FieldByName('Immagine').AsString);
End;

In the image see the red "X" painted in the WebImageControl1.URL BUT Bitmap.LoadFromResource( give me error. if you see Form is wrong with the error next !!!

Hi,

I've created a sample, with a simple JPEG base 64 string. It loads here without errors.Sample.zip (7.8 KB)

Please provide a sample, or base64 string that produces the error so we can see what exactly is going wrong. Additionally, are you using the latest version?

I discovered the problem : is the "while not eof " iteration BUT i dont known how to solve it, with separated thread ? see the code below

    DataSet.First();
    While Not DataSet.Eof Do Begin
      With Items.Add Do Begin
        Bitmap.Height:=50; Bitmap.Width:=50;
 
      // HERE THE PROBLEM 
        If DataSet.FieldByName('Immagine').AsString <> '' Then    
    
 Bitmap.LoadFromResource('data:image/jpeg;base64,'+DataSet.FieldByName('Immagine').AsString);
        End;

      End;
      // RECORD CHANGE BEFORE IMAGE IS ENTIRELY LOADED
      DataSet.Next();
    End;

help me please

Hi,

It's unclear exactly what you want to achieve. Attached is a sample that demonstrates how to add icons inside the TTMSFNCTableView. When calling Bitmap.LoadFromResource, the image is loaded asynchronously. What is the issue exactly that you are experiencing? Please explain more in detail with step by step instructions.

TableViewIconSize.zip (8.0 KB)

Your project is static better you LoadFromResource(IMG1) where IMG is a const. To me the problem is dynamic : I load an image by dataset field when it iterate