Atozed Forums
Working with PNG data - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Delphi (https://www.atozed.com/forums/forum-10.html)
+--- Forum: English (https://www.atozed.com/forums/forum-13.html)
+---- Forum: Delphi General Discussion (https://www.atozed.com/forums/forum-11.html)
+---- Thread: Working with PNG data (/thread-2736.html)



Working with PNG data - Сергей Александрович - 05-13-2022

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


RE: Working with PNG data - kudzu - 05-13-2022

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.


RE: Working with PNG data - Сергей Александрович - 05-14-2022

Thank you, you helped me. You suggested that this is Base64. And using your hint, I found a solution to the problem.


RE: Working with PNG data - rlebeau - 05-15-2022

(05-13-2022, 06:23 PM)kudzu Wrote: Is this an Indy question?

Does it matter? This was asked in a "Delphi General Discussion" forum. If non-Indy questions are not allowed here, then why does this forum exist?


RE: Working with PNG data - Сергей Александрович - 05-16-2022

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;


RE: Working with PNG data - Alexandre Machado - 04-16-2023

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;