Hi there,
Can you let me know if it's possible to enumerate the images of a TAdvRichEditor and convert them to JPEG images if they are not currently JPEGs.
Just trying to store in a smaller format to save space in the DB/network traffic.
Thanks,
Graham
Me again,
I've had a play and managed to get it working nicely. For anyone who wants to do this, here's the code...
TMS devs: feel free to use this if you want to use it as an example in any documentation, it might help someone else out there :-)
procedure TfrmTemplateEditor.ConvertImagesToJpegs;
var
ICount: integer;
AImage: TGDIPPicture;
ABmp: TBitmap;
AJpeg: TJPEGImage;
AElement: TREElement;
begin
for ICount := 0 to edtTemplate.Context.Content.Count-1 do
begin
AElement := edtTemplate.Context.Content[ICount];
if (AElement is TPictureElement) then
begin
AImage := (AElement as TPictureElement).Picture;
if AImage.PictureFormat <> pfJPG then
begin
ABmp := TBitmap.Create;
AJpeg := TJPEGImage.Create;
try
ABmp.SetSize((AElement as TPictureElement).PictureWidth, (AElement as TPictureElement).PictureHeight);
AImage.Draw(ABmp.Canvas, Rect(0,0,ABmp.Width, ABmp.Height));
AJpeg.Assign(ABmp);
AImage.Assign(AJpeg);
finally
ABmp.Free;
AJpeg.Free;
end;
end;
end;
end;
end;