converting TGraphic to jpeg or png from existing rvf
Posted: Tue Nov 08, 2016 1:14 pm
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
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....