converting TGraphic to jpeg or png from existing rvf

General TRichView support forum. Please post your questions here
Post Reply
wellington.dias
Posts: 3
Joined: Wed Jul 22, 2015 2:55 pm

converting TGraphic to jpeg or png from existing rvf

Post by wellington.dias »

I have the following procedure to convert all pictures from de rfv in jpg, I'm doing that to save more space in my database.
When I try to use, an "access violation" exception rise at the line:
RVData.GetRVData.SetPictureInfo(itemno, s, tgraphic(Jpg), VAlign, Tag);

I,m using the richview 15

Code: Select all

///procedure
procedure TForm3.EnumItemsProc(RVData: TCustomRVData; ItemNo: Integer;
  var UserData1: Integer; const UserData2: String;
  var ContinueEnum: Boolean);
var gr: TGraphic;
    jpg: TJPEGImage;
    bmp: TBitmap;
    Tag: TRVTag;
    VAlign: TRVVAlign;
    s: TRVAnsiString;
begin
    if RVData.GetItem(ItemNo) is TRVGraphicItemInfo then begin
        RVData.GetPictureInfo(ItemNo,s,gr,VAlign,Tag);
        if (gr is TPngImage) or (gr is TJPEGImage) then exit;
        ////converter imagem para bmp
        bmp := TBitmap.Create;
        try
            bmp.Assign(gr);
        except
            bmp.Width := gr.Width;
            bmp.Height := gr.Height;
            bmp.Canvas.Draw(0, 0, gr);
        end;

        ////converter imagem de bmp para jpeg
        try
            Jpg := TJPEGImage.Create;
            Jpg.Assign(Bmp);
            RVData.GetRVData.SetPictureInfo(itemno, s, tgraphic(Jpg), VAlign, Tag);
        finally
            //PNG.Free;
            jpg.Free;
        end;
        bmp.Free;
    end;
    ContinueEnum := True;
end;



///call
    sRichViewEdit1.RichViewEdit.RVData.EnumItems(EnumItemsProc, v, '');
    sRichViewEdit1.RichViewEdit.format;


///register class
 initialization
    RVGraphicHandler.RegisterJpegGraphic(TJPEGImage);


///units
uses    JPEG, PngImage, RVFuncs, CRVData,  RVGrHandler....
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do not free jpg. After calling SetPictureInfo, it is used by TRichView.
wellington.dias
Posts: 3
Joined: Wed Jul 22, 2015 2:55 pm

Post by wellington.dias »

thanks for the reply.

cool! it's working now! however the size rvf size has increased, even with the pictures conversion. Is it normal? Is it possible to decrease the pictures size?
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Probably, you should check if the existing image format, and convert only TBitmap?
At least do not convert PNG, JPEG and GIF.
Post Reply