Pictures in TRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
dikonsult
Posts: 6
Joined: Mon Mar 16, 2020 8:40 am

Pictures in TRichViewEdit

Post by dikonsult »

Hi,
I'm trying out the RichViewEdit coponent in my application for possible future use but have a problem when including pictures in the text.
With no pictures in the text I can use the code below but it will not work with pictures. I have isolated the problem to be when I'm saving the TStream to my database using LoadFromStream().

Can you figure out what I'm doing wrong here?

Regards


var
notering : TStream;

....
....
....

// Save RichViewEdit to database
ADOQtable.SQL.Add('INSERT INTO Table1');
ADOQtable.SQL.Add('Notering = :Notering');
ADOQtable.Parameters.ParseSQL(ADOQtable.SQL.Text,true);
Notering.Position := 0;
// using ftString works fine until I have pictures in my text. Which ft.. should I use with pictures included or is there another method?
ADOQtable.Parameters.ParamByName('Notering').LoadFromStream(Notering, ftString);
ADOQtable.ExecSQL;


// Read data from database to RichViewEdit
ADOQtable.Edit;
Notering := ADOQtable.Createblobstream(ADOQSelectedNTAV.FieldByName('Notering'), bmRead);

RichViewEdit1.Clear;
TStream(FNotering^).Position := 0;
RichViewEdit1.LoadRTFFromStream(Notering);
RichViewEdit1.Format;

Sergey Tkachenko
Site Admin
Posts: 15166
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Pictures in TRichViewEdit

Post by Sergey Tkachenko »

How do you save this document in the database?
Can you store content of TStream(FNotering^) to a file, and attach here, or sent to email richviewgmailcom?

dikonsult
Posts: 6
Joined: Mon Mar 16, 2020 8:40 am

Re: Pictures in TRichViewEdit

Post by dikonsult »

Sorry, it should say notering.Position := 0;

I'm saving according to the first part:
ADOQtable.SQL.Add('INSERT INTO Table1');
ADOQtable.SQL.Add('Notering = :Notering');
ADOQtable.Parameters.ParseSQL(ADOQtable.SQL.Text,true);
Notering.Position := 0;
ADOQtable.Parameters.ParamByName('Notering').LoadFromStream(Notering, ftString);
ADOQtable.ExecSQL;

and it is saved in a blob-field in my MySQL database via the parameter :Notering in my SQL.

Sory a stupid question. How do I save my stream to a file?

Regards

Sergey Tkachenko
Site Admin
Posts: 15166
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Pictures in TRichViewEdit

Post by Sergey Tkachenko »

Code: Select all

var
  FileStream: TFileStream;


FileStream := TFileStream.Create(FileName, fmCreate);
FileStream.CopyFrom(Notering, 0);
FileStream.Free;
PS:
Is FNotering equal to @Notering?

dikonsult
Posts: 6
Joined: Mon Mar 16, 2020 8:40 am

Re: Pictures in TRichViewEdit

Post by dikonsult »

Hi,
First I have to say that I'm sorry for bad debugging from my side. I did not catch the error message correctly.
Now I see that I get the error message "Data too long" when executing the SQL statement. Changing to LongBlob seems too fix it but when adding another picture I get error "Server has gone away".
I'm a little surpriced though since I only had a picture of 44kB in my text and it should not be too lagre for the blob field.
Have you had that problem before and do you know what to do?

Regards

GoranBru
Posts: 13
Joined: Wed Jan 22, 2020 2:26 pm

Re: Pictures in TRichViewEdit

Post by GoranBru »

Hi,
I had problems but I am using the dbXpress and MSSQL database. Images are stored in field of type Image as text fields for RVF format were not usable. The biggest problem was copy paste of whole page picture from MS Word 2016 as the pasted image was not in PNG format but rather EMF and the picture size to be saved was about 40 MB instead of 2MB. I did some magic when pasting image to reduce size by converting them to PNG and now it looks okay.
I hope this can help You somehow.

Best regards,
Goran

dikonsult
Posts: 6
Joined: Mon Mar 16, 2020 8:40 am

Re: Pictures in TRichViewEdit

Post by dikonsult »

Hi,
Thank's for your comment Goran.
Does anyone perhaps know if there is a way to compress the stream in the same way as we compress files with to zip-format?

Regards

Sergey Tkachenko
Site Admin
Posts: 15166
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Pictures in TRichViewEdit

Post by Sergey Tkachenko »

To save pictures in most compact way in RTF, the following options must be included in RTFOptions property:
rvrtfSaveJpegAsJpeg, rvrtfSavePngAsPng, rvrtfSaveBitmapDefault, rvrtfPNGInsteadOfBitmap.

Also, I recommend to call RichViewEdit.DeleteUnusedStyle(True, True, True) before saving to RTF.

Streams can be compressed using ZLib that is included in Delphi. However:
- PNG and JPEG images are already compressed, so their size will not be smaller;
- compressed format is not standard; and it is a binary format that can be stored in Unicode string; if you do not need to use a standard format and a text format, you may consider using our format (RVF) instead of RTF, it will be smaller.

dikonsult
Posts: 6
Joined: Mon Mar 16, 2020 8:40 am

Re: Pictures in TRichViewEdit

Post by dikonsult »

Hi and thank's for your patience with my "problems".
One last question on pictures.
I can scale pictures in RichViewEdit either with the mouse or with the ObjectProperties. But is there a way to save the picture with the new scaling or is it always stored in the original size in the document?

Regards
Dag

Sergey Tkachenko
Site Admin
Posts: 15166
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Pictures in TRichViewEdit

Post by Sergey Tkachenko »

When the user resizes a picture with the mouse, or when you set image-width/image-height item properties, the actual image is not changed. It is just displayed stretched.

I can write post a code that resize actual pictures (bitmaps, jpegs, non-transparent png) to the size in the editor, if you want.

However:
1) Sometimes it makes sense to have a picture that has an original size lager than its display size. This image will look better when printing, or when displaying this document on high DPI displays.
2) Some pictures (like screenshots or schemes) may become larger in file size when scaled down (blurred PNG images require more file size than PNG images that have clear colors).

Post Reply