Lazarus

Programming => Operating Systems => Android => Topic started by: xinyiman on November 12, 2019, 10:25:35 am

Title: image base64
Post by: xinyiman on November 12, 2019, 10:25:35 am
Goodmorning everyone. For one of my projects I'm writing a photo gallery that takes images from a json server that returns images in base64. Until now, thanks to jmpessoa I am able to understand how to create the gallery starting from the assets. But I don't understand how to put an image in the form of a base 64 in a jBitmap. I figured out how to do it with the jWebView object but this is not covered in the example of the gallery that gave me jmpessoa. I also tried to use the library I usually use with lazarus to transform a base64 into a stream, but it crashes the program (see next code).

Code: Pascal  [Select]
  1. unit funzioni_base64;
  2.  
  3. //{$mode objfpc}{$H+}
  4. {$mode delphi}
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, base64;
  10.  
  11. function StreamToBase64(AInputStream: TStream): string;
  12. function Base64ToStream(const ABase64:string; AOutStream: TStream; const AStrict: Boolean=false):Boolean;
  13. function Base64ToFile(const Base64, AFile: String): boolean;
  14. function FileToBase64(const AFile: String): string;
  15.  
  16.  
  17. implementation
  18.  
  19. function StreamToBase64(AInputStream: TStream): string;
  20. var
  21.   OutputStream: TStringStream;
  22.   Encoder: TBase64EncodingStream;
  23. begin
  24.   Result := '';
  25.  
  26.   OutputStream := TStringStream.Create('');
  27.   Encoder := TBase64EncodingStream.Create(OutputStream);
  28.  
  29.   try
  30.     AInputStream.Position := 0;
  31.     Encoder.CopyFrom(AInputStream, AInputStream.Size);
  32.     Encoder.Flush;
  33.  
  34.     OutputStream.Position := 0;
  35.  
  36.     Result := OutputStream.DataString;
  37.   finally
  38.     Encoder.Free;
  39.     OutputStream.Free;
  40.   end;
  41. end;
  42.  
  43. function Base64ToStream(const ABase64:string; AOutStream: TStream; const AStrict: Boolean=false):Boolean;
  44. var
  45.   InStream : TStringStream;
  46.   Decoder  : TBase64DecodingStream;
  47. begin
  48.   Result   := False;
  49.   InStream := TStringStream.Create(ABase64);
  50.   try
  51.     if AStrict then
  52.       Decoder := TBase64DecodingStream.Create(InStream, bdmStrict)
  53.     else
  54.       Decoder := TBase64DecodingStream.Create(InStream, bdmMIME);
  55.     try
  56.        AOutStream.CopyFrom(Decoder, Decoder.Size);
  57.        AOutStream.Position := 0;
  58.        Result := True;
  59.     finally
  60.       Decoder.Free;
  61.     end;
  62.   finally
  63.     InStream.Free;
  64.   end;
  65. end;
  66.  
  67. function Base64ToFile(const Base64, AFile: String): boolean;
  68. var
  69.   OutStream: TFileStream;
  70. begin
  71.   Result := False;
  72.   OutStream := TFileStream.Create(AFile, fmCreate or fmShareExclusive);
  73.   try
  74.      Base64ToStream(Base64, OutStream);
  75.      Result := True;
  76.   finally
  77.     Outstream.Free;
  78.   end;
  79. end;
  80.  
  81. function FileToBase64(const AFile: String): string;
  82. var
  83.   InputStream: TFileStream;
  84. begin
  85.   if not FileExists(AFile) then
  86.     Exit('');
  87.  
  88.   InputStream := TFileStream.Create(AFile, fmOpenRead or fmShareDenyWrite);
  89.   try
  90.     Result := StreamToBase64(InputStream);
  91.   finally
  92.     InputStream.Free;
  93.   end;
  94. end;
  95.  
  96. end.
  97.  


Ideas?
Title: Re: image base64
Post by: xinyiman on November 12, 2019, 10:49:54 am
First obstacle exceeded. The problem was not the library, but the base64 string. Now I can put the image in the stream. With the following code

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4nO2d7XqiMBBGwaUVQUNVqtXW2l17/9e41g+62zJkJsRMhs75uU/r5vA6YRIoJImiKIqiKIqiKIqiKIqiKIqiKIqiKMrPI1/+cqWecQ/eTj1dl6MePG1yboVOZtuyMGkfTFZsuC06qOdZL70zo2duD5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kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jImageList1.Images.LoadFromStream(appMem);
  4.   appMem.Free;  
  5.  
Title: Re: image base64
Post by: xinyiman on November 12, 2019, 10:51:46 am
But now I have the problem that I can't get this code displayed. I tried this but the program crashed

Code: Pascal  [Select]
  1.  
  2.   jBitmap1.Images := jImageList1;
  3.   jBitmap1.ImageIndex:=0;
  4.   bmp := jBitmap1.GetImage();
  5.   jHorizontalScrollView1.AddImage(bmp,105, scaleFitXY);  
  6.  
  7.  
Title: Re: image base64
Post by: xinyiman on November 12, 2019, 11:50:48 am
Now i test this code. Application run but not show my image.  %) %)

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4nO2d7XqiMBBGwaUVQUNVqtX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ESG1FaFkKGpp30AQjCNCciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jBitmap1.LoadFromBuffer(appMem, appMem.Size);
  4.   bmp := jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  5.   jHorizontalScrollView1.AddImage(bmp,109, scaleFitXY);
  6.   appMem.Free;  

Title: Re: image base64
Post by: Thaddy on November 12, 2019, 01:50:41 pm
Post a *complete* - but small - project, plz
This is impossible to test because the code looks reasonable but is not a full application.
Title: Re: image base64
Post by: xinyiman on November 12, 2019, 02:02:18 pm
Source is jmpessoa example with name: AppScrollingImages

But i add this unit

Code: Pascal  [Select]
  1.     unit funzioni_base64;
  2.      
  3.     //{$mode objfpc}{$H+}
  4.     {$mode delphi}
  5.      
  6.     interface
  7.      
  8.     uses
  9.       Classes, SysUtils, base64;
  10.      
  11.     function StreamToBase64(AInputStream: TStream): string;
  12.     function Base64ToStream(const ABase64:string; AOutStream: TStream; const AStrict: Boolean=false):Boolean;
  13.     function Base64ToFile(const Base64, AFile: String): boolean;
  14.     function FileToBase64(const AFile: String): string;
  15.      
  16.      
  17.     implementation
  18.      
  19.     function StreamToBase64(AInputStream: TStream): string;
  20.     var
  21.       OutputStream: TStringStream;
  22.       Encoder: TBase64EncodingStream;
  23.     begin
  24.       Result := '';
  25.      
  26.       OutputStream := TStringStream.Create('');
  27.       Encoder := TBase64EncodingStream.Create(OutputStream);
  28.      
  29.       try
  30.         AInputStream.Position := 0;
  31.         Encoder.CopyFrom(AInputStream, AInputStream.Size);
  32.         Encoder.Flush;
  33.      
  34.         OutputStream.Position := 0;
  35.      
  36.         Result := OutputStream.DataString;
  37.       finally
  38.         Encoder.Free;
  39.         OutputStream.Free;
  40.       end;
  41.     end;
  42.      
  43.     function Base64ToStream(const ABase64:string; AOutStream: TStream; const AStrict: Boolean=false):Boolean;
  44.     var
  45.       InStream : TStringStream;
  46.       Decoder  : TBase64DecodingStream;
  47.     begin
  48.       Result   := False;
  49.       InStream := TStringStream.Create(ABase64);
  50.       try
  51.         if AStrict then
  52.           Decoder := TBase64DecodingStream.Create(InStream, bdmStrict)
  53.         else
  54.           Decoder := TBase64DecodingStream.Create(InStream, bdmMIME);
  55.         try
  56.            AOutStream.CopyFrom(Decoder, Decoder.Size);
  57.            AOutStream.Position := 0;
  58.            Result := True;
  59.         finally
  60.           Decoder.Free;
  61.         end;
  62.       finally
  63.         InStream.Free;
  64.       end;
  65.     end;
  66.      
  67.     function Base64ToFile(const Base64, AFile: String): boolean;
  68.     var
  69.       OutStream: TFileStream;
  70.     begin
  71.       Result := False;
  72.       OutStream := TFileStream.Create(AFile, fmCreate or fmShareExclusive);
  73.       try
  74.          Base64ToStream(Base64, OutStream);
  75.          Result := True;
  76.       finally
  77.         Outstream.Free;
  78.       end;
  79.     end;
  80.      
  81.     function FileToBase64(const AFile: String): string;
  82.     var
  83.       InputStream: TFileStream;
  84.     begin
  85.       if not FileExists(AFile) then
  86.         Exit('');
  87.      
  88.       InputStream := TFileStream.Create(AFile, fmOpenRead or fmShareDenyWrite);
  89.       try
  90.         Result := StreamToBase64(InputStream);
  91.       finally
  92.         InputStream.Free;
  93.       end;
  94.     end;
  95.      
  96.     end.
  97.  

But i change AndroidModule1JNIPrompt procedure with this code:

Code: Pascal  [Select]
  1. var
  2.   bmp        : jObjectRef;
  3.   strDensity : string;
  4.   list       : TStringList;
  5.   appMem     : TMemoryStream;
  6. begin
  7.  
  8.   //WARNING:  jHorizontalScrollView1.InnerLayout -> ilLinear;  //MUST be seted in design time! [object inspector]
  9.   //LinearLayout dont need anchor!!
  10.  
  11.   strDensity := Self.GetScreenDensity();
  12.   Self.SetDensityAssets(strDensity);
  13.  
  14.   bmp := jBitmap1.GetThumbnailImageFromAssets('baloons.jpg', jHorizontalScrollView1.Height);
  15.   jHorizontalScrollView1.AddImage(bmp,101, scaleFitXY);
  16.  
  17.   bmp := jBitmap1.GetThumbnailImageFromAssets('lightning.jpg',jHorizontalScrollView1.Height);
  18.   jHorizontalScrollView1.AddImage(bmp,102, scaleFitXY);
  19.  
  20.   bmp := jBitmap1.GetThumbnailImageFromAssets('wall.jpg',jHorizontalScrollView1.Height);
  21.   jHorizontalScrollView1.AddImage(bmp,103, scaleFitXY);
  22.  
  23.   bmp := jBitmap1.GetThumbnailImageFromAssets('veneza.jpg',jHorizontalScrollView1.Height);
  24.   jHorizontalScrollView1.AddImage(bmp,104, scaleFitXY);
  25.  
  26.   appMem := TMemoryStream.Create;
  27.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4nO2d7XqiMBBGwaUVQUNVqtXW2l17/9e41g+62zJkJsR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CciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  28.   appMem.Position:=0;
  29.   jBitmap1.LoadFromBuffer(appMem, appMem.Size);
  30.   bmp := jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  31.   jHorizontalScrollView1.AddImage(bmp,108, scaleFitXY);
  32.   appMem.Free;
  33.  
  34.  
Title: Re: image base64
Post by: A.S. on November 12, 2019, 08:53:57 pm
Now i test this code. Application run but not show my image.  %) %)

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4n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NpQswwigiprQhFUGIVthtCdyXEESG1FaFkKGpp30AQjCNCciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jBitmap1.LoadFromBuffer(appMem, appMem.Size);
  4.   bmp := jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  5.   jHorizontalScrollView1.AddImage(bmp,109, scaleFitXY);
  6.   appMem.Free;  

Try
jBitmap1.LoadFromBuffer(appMem.Memory, appMem.Size)
Title: Re: image base64
Post by: xinyiman on November 13, 2019, 08:58:40 am
Now i test this code. Application run but not show my image.  %) %)

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6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NgOBtKFUKG7+13WMdeha2Hv91jATwPU9Si4kL7z0JEESGxFQF+GPhncRNpQswwigiprQhFUGIVthtCdyXEESG1FaFkKGpp30AQjCNCciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jBitmap1.LoadFromBuffer(appMem, appMem.Size);
  4.   bmp := jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  5.   jHorizontalScrollView1.AddImage(bmp,109, scaleFitXY);
  6.   appMem.Free;  

Try
jBitmap1.LoadFromBuffer(appMem.Memory, appMem.Size)

Not solved.
Title: Re: image base64
Post by: chenyuchih on November 13, 2019, 10:38:30 am
Is it possible that the string is not an jbitmap stream format after decoding?

Did you try loading a image to stream, encoding the stream to string, decoding the string back to new stream, and compared the new stream with the original one? Maybe these steps could help finding the problem.

ChenYuChih
Title: Re: image base64
Post by: xinyiman on November 13, 2019, 10:52:50 am
It seems absurd to me. JBitmap correctly displays the image if I pass it in another way. I take the same image and I transform it to base64 and I don't see it anymore.

Title: Re: image base64
Post by: xinyiman on November 13, 2019, 11:29:45 am
If change code from

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4nO2d7XqiMBBGwaUVQUNVqtXW2l17/9e41g+62zJkJsRMhs75uU/r5vA6YRIoJImiKIqiKIqiKIqiKIqiKIqiKIqiKMrPI1/+cqWecQ/eTj1dl6MePG1yboVOZtuyMGkfTFZsuC06qOdZL70zo2duD5Dc9MvvSvHAbQLxUnkRjFdxM/YkGKvizFeC0SruRh4No1Tc+swwSsVXPxNpxIoHz4bxKfoWPPY35f0tMC/7P06G3gVvhinK9dugDdOPr8fvgRumafY6dMM0Ww3dMC13Qzc066EbpiXxpME9XjrFfuiGhtg0tX9Kgd2C8t8S2TEeDIsFch9x+VAE1jty78Ewu0P/PoNiYEMGxdCG4RWDGwZXDG8YWpHBMLAih2FYRRbD5Hkc7tzPY5hMR8FiZDJM6lVVjjO/tO/lchkeedzd+WXVqsho6J271gubavgFNWRFDVGoIStqiEINWWE0rJ3v8iOxaO3mR/b/fVn3MlxO5qNe9/mhAZYr9l8sy/midjbsfZtfEExR7t0M6znDHrAb2SF3MKwrAfldqdKabrj2e4PRjaleyIYeb/MLwnhDNMwD7jf5wRANJ2JmmSvjN5Lh7D7w+PpTbUmG8iJMzRPFUF4VHg0PFEOBEabpnGCYs1y074l5JRiKjLDa4w0lVuFxGbLDG4qMMK3wZ3yZERYTvOFUYoSmzNGGIifSU4RYQ5FVaMY52lBuFWINwQhvvxtlB1qUmxF+FyMvIcHHAHuKtp3D9ivFxwinCdoQivD8NWBmlrVX0LkKcYZQFV4/gxfb4ccYRh0hePizy+FHGEJL+9P5lB2oFWkOP8Iw7giBVuQykSYYQ9lViDGMO0JbFSIM7V8DThCH32oIfsaUQegrYCtSfj6MxGYovQrthjKr8N/DbzFEVDIjqMNvMbSeTznBtSLdhuIn0sRmKL8KLYYDqEKLYdwRIiuoyxBzPuUD24p0GcYdIbYV6TCU386c6DCUGeG3SRA2FL60b4AN444Q34qAhgOpwg7DuCMktCKQ4RA60jOQofilfQNgOBtKFUKG7+13WMdeha2Hv91jATwPU9Si4kL7z0JEESGxFQF+GPhncRNpQswwigiprQhFUGIVthtCdyXEESG1FaFkKGpp30AQjCNCciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jBitmap1.LoadFromBuffer(appMem.Memory, appMem.Size);
  4.   bmp := jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  5.   jHorizontalScrollView1.AddImage(bmp,108, scaleFitXY);
  6.   appMem.Free;          
  7.  

to

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4nO2d7XqiMBBGwaUVQUNVqtXW2l17/9e41g+62zJkJsRMhs75uU/r5vA6YRIoJImiKIqiKIqiKIqiKIqiKIqiKIqiKMrPI1/+cqWecQ/eTj1dl6MePG1yboVOZtuyMGkfTFZsuC06qOdZL70zo2duD5Dc9MvvSvHAbQLxUnkRjFdxM/YkGKvizFeC0SruRh4No1Tc+swwSsVXPxNpxIoHz4bxKfoWPPY35f0tMC/7P06G3gVvhinK9dugDdOPr8fvgRumafY6dMM0Ww3dMC13Qzc066EbpiXxpME9XjrFfuiGhtg0tX9Kgd2C8t8S2TEeDIsFch9x+VAE1jty78Ewu0P/PoNiYEMGxdCG4RWDGwZXDG8YWpHBMLAih2FYRRbD5Hkc7tzPY5hMR8FiZDJM6lVVjjO/tO/lchkeedzd+WXVqsho6J271gubavgFNWRFDVGoIStqiEINWWE0rJ3v8iOxaO3mR/b/fVn3MlxO5qNe9/mhAZYr9l8sy/midjbsfZtfEExR7t0M6znDHrAb2SF3MKwrAfldqdKabrj2e4PRjaleyIYeb/MLwnhDNMwD7jf5wRANJ2JmmSvjN5Lh7D7w+PpTbUmG8iJMzRPFUF4VHg0PFEOBEabpnGCYs1y074l5JRiKjLDa4w0lVuFxGbLDG4qMMK3wZ3yZERYTvOFUYoSmzNGGIifSU4RYQ5FVaMY52lBuFWINwQhvvxtlB1qUmxF+FyMvIcHHAHuKtp3D9ivFxwinCdoQivD8NWBmlrVX0LkKcYZQFV4/gxfb4ccYRh0hePizy+FHGEJL+9P5lB2oFWkOP8Iw7giBVuQykSYYQ9lViDGMO0JbFSIM7V8DThCH32oIfsaUQegrYCtSfj6MxGYovQrthjKr8N/DbzFEVDIjqMNvMbSeTznBtSLdhuIn0sRmKL8KLYYDqEKLYdwRIiuoyxBzPuUD24p0GcYdIbYV6TCU386c6DCUGeG3SRA2FL60b4AN444Q34qAhgOpwg7DuCMktCKQ4RA60jOQofilfQNgOBtKFUKG7+13WMdeha2Hv91jATwPU9Si4kL7z0JEESGxFQF+GPhncRNpQswwigiprQhFUGIVthtCdyXEESG1FaFkKGpp30AQjCNCciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jBitmap1.LoadFromBuffer(appMem.Memory, appMem.Size);
  4.   bmp := jBitmap1.GetImage(); //jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  5.   jHorizontalScrollView1.AddImage(bmp,108, scaleFitXY);
  6.   appMem.Free;          
  7.  

I see the image. But is not ThumbnailImage. For me is a bug of lamw.
Title: Re: image base64
Post by: xinyiman on November 14, 2019, 09:39:04 am
In this way the code works. So I am increasingly inclined to think that there is a bug in: GetThumbnailImage

Code: Pascal  [Select]
  1.   appMem := TMemoryStream.Create;
  2.   Base64ToStream('iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///8AWpwATJXc4+wAUZiluNEAR5MAT5fx9vmDo8UAU5kAS5WFpMX1+fsAWJsAVZo4cqkAXJ2Op8fe5+/o7/XX4OtqkLkeZqM4c6qWsM11mb9Lfq8sa6W+zuBAeK1+nsK4y91ah7XJ1+UVYqCxwdbk4OdXAAAE7UlEQVR4nO2d7XqiMBBGwaUVQUNVqtXW2l17/9e41g+62zJkJsRMhs75uU/r5vA6YRIoJImiKIqiKIqiKIqiKIqiKIqiKIqiKMrPI1/+cqWecQ/eTj1dl6MePG1yboVOZtuyMGkfTFZsuC06qOdZL70zo2duD5Dc9MvvSvHAbQLxUnkRjFdxM/YkGKvizFeC0SruRh4No1Tc+swwSsVXPxNpxIoHz4bxKfoWPPY35f0tMC/7P06G3gVvhinK9dugDdOPr8fvgRumafY6dMM0Ww3dMC13Qzc066EbpiXxpME9XjrFfuiGhtg0tX9Kgd2C8t8S2TEeDIsFch9x+VAE1jty78Ewu0P/PoNiYEMGxdCG4RWDGwZXDG8YWpHBMLAih2FYRRbD5Hkc7tzPY5hMR8FiZDJM6lVVjjO/tO/lchkeedzd+WXVqsho6J271gubavgFNWRFDVGoIStqiEINWWE0rJ3v8iOxaO3mR/b/fVn3MlxO5qNe9/mhAZYr9l8sy/midjbsfZtfEExR7t0M6znDHrAb2SF3MKwrAfldqdKabrj2e4PRjaleyIYeb/MLwnhDNMwD7jf5wRANJ2JmmSvjN5Lh7D7w+PpTbUmG8iJMzRPFUF4VHg0PFEOBEabpnGCYs1y074l5JRiKjLDa4w0lVuFxGbLDG4qMMK3wZ3yZERYTvOFUYoSmzNGGIifSU4RYQ5FVaMY52lBuFWINwQhvvxtlB1qUmxF+FyMvIcHHAHuKtp3D9ivFxwinCdoQivD8NWBmlrVX0LkKcYZQFV4/gxfb4ccYRh0hePizy+FHGEJL+9P5lB2oFWkOP8Iw7giBVuQykSYYQ9lViDGMO0JbFSIM7V8DThCH32oIfsaUQegrYCtSfj6MxGYovQrthjKr8N/DbzFEVDIjqMNvMbSeTznBtSLdhuIn0sRmKL8KLYYDqEKLYdwRIiuoyxBzPuUD24p0GcYdIbYV6TCU386c6DCUGeG3SRA2FL60b4AN444Q34qAhgOpwg7DuCMktCKQ4RA60jOQofilfQNgOBtKFUKG7+13WMdeha2Hv91jATwPU9Si4kL7z0JEESGxFQF+GPhncRNpQswwigiprQhFUGIVthtCdyXEESG1FaFkKGpp30AQjCNCciuCFxTYzpxoMREZITwJ4iMUtrRvQBvGEaHDmg4dodAq/G44tCpEZyiyIz2DNJS3tG9ARii2Cr8ayqzC7sOPi1DkouKCnAhdrzKgIpQ7kSY4wygidL7KgIlQchX+Zxh1FbpfZUBkKHNp32AXjCNC96sMVkHJ7cyJTxORESImQWuEUpf2DTbDOCLsc7nWFqH0KmwMB1uFtgxld6Rnug0FL+0buiOUX4UXQ5lViDz8nRFmUXekyMPfFWG1cn+DrjcegdcXoluRrgzTivuPmD8AxoauoE7DiMFPgtwjdQU/CcJVGDWEVoR7qI4QWhHuobpBaUW4x+oGpRXhHqsTpP1N7sE6QeomuQfrAm1Nxz1aF2gLgjn3cOkQrzIcuMdLh7imgx5fEzHEqwzvwp6bS1+WQ0/oiRb6zsq09dn18ZLRN8e8v139ppg5WTCpJTxE/orJlnTDZFmJeaBeUbkIHmebVSnCsShXzpt/y70J8z6HPpitW4BXAr2Uw53a7qAoiqIoiqIoiqIoiqIoiqIoiqIoivKz+QtcBHyrUyhNmAAAAABJRU5ErkJggg==',appMem);
  3.   jBitmap1.LoadFromBuffer(appMem.Memory, appMem.Size);
  4.   //bmp := jBitmap1.GetThumbnailImage(jBitmap1.GetImage(), jHorizontalScrollView1.Height);
  5.   bmp := jBitmap1.GetResizedBitmap(jBitmap1.GetImage(), jHorizontalScrollView1.Height, jHorizontalScrollView1.Height);
  6.   jHorizontalScrollView1.AddImage(bmp,108, scaleFitXY);
  7.   appMem.Free;
  8.  
Title: Re: image base64
Post by: kordal on November 14, 2019, 10:14:23 am
If you open jBitmap.java and look at the GetThumbnailImage(Bitmap _bitmap, int _thumbnailSize) method, it immediately becomes clear why it does not work.
Code: Java  [Select]
  1. public Bitmap GetThumbnailImage(Bitmap _bitmap, int _thumbnailSize) {
  2.         Bitmap thumbnailImage = null;
  3.         try {
  4.             int width = thumbnailImage.getWidth();
  5.             int height = thumbnailImage.getHeight();
  6.             float ratio = width/height;
  7.  
  8.             if (width >= height)
  9.                 ratio = width/height;
  10.             else
  11.                 ratio = height/width;
  12.  
  13.             thumbnailImage = ThumbnailUtils.extractThumbnail(thumbnailImage,(int)(_thumbnailSize * ratio), _thumbnailSize);
  14.             //imageBitmap = Bitmap.createScaledBitmap(_bitmap, (int)(_thumbnailSize * ratio), _thumbnailSize, false);
  15.         }
  16.         catch(Exception ex) {
  17.             //
  18.         }
  19.         return thumbnailImage;
  20.     }
  21.  

Use another method GetThumbnailImage (Bitmap _bitmap, int _width, int _height), or edit the current one.

I would do it like this:
Code: Java  [Select]
  1. public Bitmap GetThumbnailImage(Bitmap _bitmap, int _thumbnailSize) {
  2.         Bitmap thumbnailImage = null;
  3.         try {
  4.             int width = _bitmap.getWidth();
  5.             int height = _bitmap.getHeight();
  6.             float ratio = width / height;
  7.  
  8.             if (width >= height)
  9.                 ratio = width / height;
  10.             else
  11.                 ratio = height / width;
  12.  
  13.             thumbnailImage = ThumbnailUtils.extractThumbnail(_bitmap, (int)(_thumbnailSize * ratio),  _thumbnailSize);
  14.         }
  15.         catch(Exception ex) {
  16.             //
  17.         }
  18.         return thumbnailImage;
  19.     }
  20.  

In Laz_and_controls.pas unit, you can add method: LoadFromStream (Stream: TStream)
Code: Pascal  [Select]
  1. //....
  2.   jBitmap = class(jControl)
  3.   // ...
  4.   public
  5.     procedure LoadFromStream(Stream: TStream);
  6.   // ...
  7.   end;
  8.  
  9.   implementation
  10.  
  11.   // ...
  12.   procedure jBitmap.LoadFromStream(Stream: TStream);
  13.   begin
  14.     if FInitialized then
  15.       jBitmap_LoadFromBuffer(FjEnv, FjObject, Stream.Memory, Stream.Size);    
  16.   end;
  17.  
Title: Re: image base64
Post by: xinyiman on November 14, 2019, 04:40:23 pm
Thanks for the tips But I don't want to touch the Lamw code. Because maintained by jmpessoa. If he then updates something I lose everything in the next update. I hope he updates the project with your advice.
Title: Re: image base64
Post by: jmpessoa on November 14, 2019, 06:26:33 pm
Ok!

I will commit the kordal fix and improvemments!

Thanks!

Edited:

Done!!!!!
Title: Re: image base64
Post by: kordal on November 14, 2019, 10:46:21 pm
Late noticed, this is not critical, there is one unnecessary division:
Code: Java  [Select]
  1.  float ratio = width / height;
  2.  
replace:
Code: Java  [Select]
  1.  float ratio = 1;
  2.