Posts: 114
Threads: 32
Joined: Dec 2019
Reputation:
1
Location: Россия
05-13-2022, 05:17 PM
(This post was last modified: 05-13-2022, 05:18 PM by Сергей Александрович.)
Good time of day!
I've never worked with images. Now there is a need to display the image received from the server.
Here is the response I get from the server as a result of the request:
{"code":"000","message":"Запрос обработан успешно","data":{"image":{"mediaType":"image/png","content":"iVBORw0KGgoAAAAN....................."}}}
Please tell me how to display the received image in the "content" parameter on the screen. I use Delphi
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
Is this an Indy question? Indy can decode Base64 which that looks to be. If so please use the Indy forum that also exists here.
Posts: 114
Threads: 32
Joined: Dec 2019
Reputation:
1
Location: Россия
Thank you, you helped me. You suggested that this is Base64. And using your hint, I found a solution to the problem.
Posts: 114
Threads: 32
Joined: Dec 2019
Reputation:
1
Location: Россия
05-16-2022, 05:15 AM
(This post was last modified: 05-16-2022, 05:18 AM by Сергей Александрович.)
I didn't know that this problem could be solved by Indy, so I wrote to the Delphi forum. And in the end I solved the problem without Indy. Thanks again.
uses pngimage, EncdDecd
procedure TfmViewQRC.ShowQRC(mContent: String);
var
mStream1 : TMemoryStream;
mStream2 : TMemoryStream;
mPng : TPngobject;
begin
mStream1 := TMemoryStream.Create;
mStream2 := TMemoryStream.Create;
mPng := TPNGObject.Create;
try
mStream1.WriteBuffer(mContent[1],Length(mContent)*SizeOf(Char));
mStream1.Position:=0;
DecodeStream(mStream1,mStream2);
mStream2.Position := 0;
mPng.LoadFromStream(mStream2);
Image1.Canvas.Draw(0,0,mPng);
finally
mStream1.Destroy;
mStream2.Destroy;
mPng.Destroy;
end;
end;
Posts: 2,248
Threads: 191
Joined: Mar 2018
Reputation:
86
Location: Auckland, New Zealand
For future reference, IntraWeb has a unit IWImageUtils which has some utility functions to handle this issue:
procedure GraphicToBase64Str(Input: TGraphic; var Output: string);
procedure Base64StrToGraphic(var Input: string; Output: TGraphic);
function CreateGraphicFromBase64Str(var Input: string): TGraphic;
procedure Base64StrToPng(var Input: string; Output: TPngImage);
procedure Base64StrToJpg(var Input: string; Output: TJpegImage);
procedure Base64StrToGif(var Input: string; Output: TGifImage);
function Base64StrToImageFile(var Input, AFileName: string): Boolean;