Page 1 of 1

QrCode Inserted as bmp

Posted: Tue Apr 21, 2020 9:02 am
by pgkammath
HI,
I am generating a Qrcode via an API, which returns the Qrcode as a BMP file. This file a insert into a Scalerichview as per the function given below. After inserting, the this image is seen as a dot. I am able to click this image and change the properties. After that is image is show correctly. I am using this in an editor. Ataching the properties image for reference. I understand this has something to do with the style may be.

The following is the function

procedure TTextEditorNewForm.InsertQrCode(cCertId:String);
var mStream : TMemoryStream;
bmp : TBitmap;
begin
mstream := TMemoryStream.Create;
try
IdHttp2.Get('http://172.16.15.10:5002/getcertificate/'+ cCertId,mstream);
mstream.Position := 0;
AdvPicture1.Picture.LoadFromStream(mstream);
AdvPicture1.Picture.SaveToFile(ExtractFilePath(Application.ExeName)+'certid.bmp');
finally
FreeAndNil(Mstream);
end;

bmp := TBitmap.Create;
bmp.LoadFromFile(ExtractFilePath(Application.ExeName)+'certid.bmp');

with TextEdit.RichViewEdit do begin
//AddTextNL(' ',rvsKeyword,0,0);
AddTextNL(' ',rvsNormal,0,0);

AddPicture('', bmp, -1);
SetItemExtraIntProperty(ItemCount - 1, rvepImageHeight, 30);
SetItemExtraIntProperty(ItemCount - 1, rvepImageWidth , 30);

//AddTextNL(' ',rvsKeyword,0,0);
AddTextNL(' ',rvsNormal,0,0);
Format;
end;
end;

Kindly help.

Thanks in advance

Re: QrCode Inserted as bmp

Posted: Tue Apr 21, 2020 9:31 am
by Sergey Tkachenko
Obviously, it happens because not pixels, but twips or EMU are used as measure units, so 30 is a too small size.
Change the resizing code to:

Code: Select all

SetItemExtraIntProperty(ItemCount - 1, rvepImageHeight, Style.StandardPixelsToUnits(30));
SetItemExtraIntProperty(ItemCount - 1, rvepImageWidth , Style.StandardPixelsToUnits(30));

Re: QrCode Inserted as bmp

Posted: Tue Apr 21, 2020 10:23 am
by pgkammath
Problem solved.
Thanks
Regards,

Re: QrCode Inserted as bmp

Posted: Tue Apr 21, 2020 1:49 pm
by Sergey Tkachenko
By the way, is smooth scaling OK for these QrCodes? Maybe I should add a property to an image item to disable smooth scaling?