Dear Sir,
I am using TImageEnvect component (vers 4.3.0) with Image Kind IEKMemo in a tool. I wanted to achieve the following
- Insert an image into the component
- Add single or multiple text controls -> we used IEKMemo kind here
- Should change the text color, font size
- Save the image.
Here it should be possible to save the image at any time. i.e after adding single text or multiple texts
I made this but frequently i am getting Access violation and list index out of bounds issue.
I have attached the codesnippets used for changing the font color and size etc and then methods to save the image
Could you please advise me to overcome these issues ?
Code to change the font color and size
Procedure Tftext.TryChangeFontSize(aImgPreview : TImageEnVect) ;
Var
iCTR, iSelObj : Integer ;
Begin
For iCTR := 0 to aImgPreview.SelObjectsCount-1 do begin
iSelObj := aImgPreview.SelObjects[iCTR];
aImgPreview.ObjFontHeight[iSelObj] := CharInfo.Font.Size ;
//aImgPreview.ObjFontStyles[iSelObj] := CharInfo.Font.Style ;
if BoldButton.Down then
CharInfo.Font.Style := CharInfo.Font.Style + [fsBold]
else
CharInfo.Font.Style := CharInfo.Font.Style - [fsBold];
if ItalicButton.Down then
CharInfo.Font.Style := CharInfo.Font.Style + [fsItalic]
else
CharInfo.Font.Style := CharInfo.Font.Style - [fsItalic];
if UnderlineButton.Down then
CharInfo.Font.Style := CharInfo.Font.Style + [fsUnderline]
else
CharInfo.Font.Style := CharInfo.Font.Style - [fsUnderline];
aImgPreview.ObjFontName[iSelObj] := FontName.Text;
aImgPreview.ObjFontStyles[iSelObj] := CharInfo.Font.Style ;
//aImgPreview.ObjTextEditable[iSelObj] := True ;
aImgPreview.Update ;
end;
End;
-----------------------
procedure Tftext.Controls2MemoText(Sender: TObject);
var
sText: String;
// iCurrobj: Integer;
begin
if not changing then
begin
changing := True;
// sText := TImageEnvect(frmViewImage.PopupMenu.PopupComponent).ObjText[TImageEnvect(frmViewImage.PopupMenu.PopupComponent).SelObjects[0]];
if frmViewImage.pgReport.TabIndex = 0 then
CharInfo := frmViewImage.Imgpreview1.MemoEditingGetCharInfo
else
CharInfo := frmViewImage.Imgpreview2.MemoEditingGetCharInfo;
// font
if BoldButton.Down then
CharInfo.Font.Style := CharInfo.Font.Style + [fsBold]
else
CharInfo.Font.Style := CharInfo.Font.Style - [fsBold];
if ItalicButton.Down then
CharInfo.Font.Style := CharInfo.Font.Style + [fsItalic]
else
CharInfo.Font.Style := CharInfo.Font.Style - [fsItalic];
if UnderlineButton.Down then
CharInfo.Font.Style := CharInfo.Font.Style + [fsUnderline]
else
CharInfo.Font.Style := CharInfo.Font.Style - [fsUnderline];
CharInfo.Font.Name := FontName.Text;
CharInfo.Font.Size := StrToIntDef(FontSize.Text, 10);
CharInfo.Font.Color := ColorSelect.Brush.Color;
// align
if LeftAlign.Down then
CharInfo.Align := iejLeft;
if CenterAlign.Down then
CharInfo.Align := iejCenter;
if RightAlign.Down then
CharInfo.Align := iejRight;
if JustifyAlign.Down then
CharInfo.Align := iejJustify;
if frmViewImage.pgReport.TabIndex = 0 then
Begin
frmViewImage.Imgpreview1.MemoEditingSetCharInfo(CharInfo);
TryChangeFontSize(frmViewImage.Imgpreview1);
End
Else
Begin
frmViewImage.Imgpreview2.MemoEditingSetCharInfo(CharInfo);
TryChangeFontSize(frmViewImage.Imgpreview2);
End;
//CharInfo.free;
changing := false;
end;
end;
-------------------------------------------------------------------------
Code to save image with multiple objects
Procedure TfrmViewImage.SaveImage(aImg : TImageEnVect; abFirstRep : Boolean);
var
sTempFile : String;
iCntrlCnt : Integer;
iObjCTR : Integer ;
Begin
Try
if aImg.ObjectsCount > 0 then Begin
ResetFontColor(aImg) ;
aImg.CopyObjectsToBack(true);
ResetFontColor(aImg) ; //doesn't change yet
sTempFile := GetTempFileNameforSave(abFirstRep);
aImg.IO.SaveToFileJpeg(sTempFile);
aImg.RemoveAllObjects;
if abFirstRep then Begin
for iCntrlCnt := 0 to pnlFirstReport.ControlCount - 1 do Begin
if (pnlFirstReport.Controls[iCntrlCnt] is TImageEnVect) and (UpperCase(pnlFirstReport.Controls[iCntrlCnt].Name) = 'IMGREP'+ IntToStr(aImg.Tag)) then Begin
TImageEnVect(pnlFirstReport.Controls[iCntrlCnt]).IO.LoadFromFileJpeg(sTempFile);
Break;
End Else {no need};
End; {end of for loop}
End Else Begin
for iCntrlCnt := 0 to pnlSecondReport.ControlCount - 1 do Begin
if (pnlSecondReport.Controls[iCntrlCnt] is TImageEnVect) and (UpperCase(pnlSecondReport.Controls[iCntrlCnt].Name) = 'IMGREP'+ IntToStr(aImg.Tag)) then Begin
TImageEnVect(pnlSecondReport.Controls[iCntrlCnt]).IO.LoadFromFileJpeg(sTempFile);
Break;
End Else {no need};
End; {end of for loop}
End;
End Else {no need};
Except
On E : Exception do Begin
CodeSite.Send('Error in saving modified image - ' + E.Message);
Showmessage('Unable to save the image ' + #13+#10+#10 + E.Message);
End;
End;
End;
TIA
Venkatesan
attach/ksvenkat/2020121711620_codeforedit_fontchanges.txt
attach/ksvenkat/2020121711712_CodeToSave with objects.txt
ksvenkat77