Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with PNG data
#1
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
Reply
#2
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.
Reply
#3
Thank you, you helped me. You suggested that this is Base64. And using your hint, I found a solution to the problem.
Reply
#4
(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?

Reply
#5
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;
Reply
#6
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;
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)