FNCChat: How do I add a image to a message WITHOUT having to write it do disk first ?

Dear friends,

From the documentation it appears as if I can add a message with an image, without having to write the image to disk first, how do I do that ?

The image is a bitmap.

When I look into the TTMSFNCCustomChat.AddImageInternal() it doesn't really look like it's possible, but I can of course be completely imstaken..

Hi,

We'll look to make the documentation more clear on this. The helper methods are there to load an image directly from the disk based on a path.

However it's also a good suggestion to be able to add the images directly from a bitmap (and in that case also as a base64 url), so we'll put this on our list.

Currently you have two options, in both cases you need to manually add the message:

  • Use a base64 representation of the image (src := Base64EncodedImage)
  • Add the image to a TTMSFNCBitmapContainer and assign the TTMSFNCBitmapContainer to the TTMSFNCChat (src := NameOfBitmapInBitmapContainer)

Then you'll need to set the Text property of the message to something like:

chatMessage.Text := '<img width="' + IntToStr(MyImageWidth) + '" src="' + src + '"/>';

//if you want some text with it, you can put it before/after the <img> tag, and put a <br> inbetween:
//chatMessage.Text := '<img width="' + IntToStr(MyImageWidth) + '" src="' + src + '"/><br>' + MyText;

Right..

I tried it this way:

NewChatItem.Bitmap := TTMSFNCBitmap.Create;
ImageDataStream := Base64DecodeToStream(MsgMiniature);
NewChatItem.Bitmap.LoadFromStream(ImageDataStream);
ImageDataStream.Free;

Because, I need the "Name" property of the image, to hold the original filename, so the user can download the file from a remote repository.

Is this method supported as well ?

Doing it that way I discovered, shows the image next to the message and not embedded in it, which I think looks real neat..

Yes, that is also a valid approach, although as you have noticed the image placement will differ.

However, if you meant the BitmapName property, then you should be aware that it is used in combination the BitmapContainer. When a TTMSFNCBitmapContainer is assigned, you can assign the Bitmap based on the name of it.

I'd suggest to use the ChatItem.DataString public property instead to store any string-based data for a chat message item, this way you can avoid accidents if you decide to use a BitmapContainer in the future (painting the image from a BitmapContainer tends to be more performant).

I understand, thank you very much.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.