Page 1 of 1

converting TGraphic to jpeg or png from existing rvf

Posted: Tue Nov 08, 2016 1:14 pm
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....

Posted: Tue Nov 08, 2016 3:57 pm
by Sergey Tkachenko
Do not free jpg. After calling SetPictureInfo, it is used by TRichView.

Posted: Tue Nov 08, 2016 4:47 pm
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?

Posted: Tue Nov 08, 2016 8:21 pm
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.