Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Android: Saving a image from datasource blob field recive from DataSnap server

Discussion in 'Delphi Help&Requests' started by programistait, Sep 19, 2014.

  1. programistait
    Offline

    programistait DF Junior

    Hello

    I got problem

    application in mobile FireMonkey with SQLite on Android, server DataSnap connected do MSSQL

    server DS have  function to send data to mobile application as DataSource

    ex:

    1. on DataSnap server function for send datasource:


    function TServerMethods1.SendDataFromServer: TDataSet;
    var
       cds: TClientDataSet;
    begin
         with ADQuery do
         begin
              Close;

              SQL.Clear;

              SQL.Add('select ID, NAME, PICTURE from LIST');

              Open;

              if FieldByName('ID').AsInteger>0 then
              begin
                   cds:=TClientDataSet.Create(Self);
                   cds.FieldDefs.Add('ID', ftInteger, 0, True);
                   cds.FieldDefs.Add('NAME', ftWideString, 100, True);
                   cds.FieldDefs.Add('PICTURE', ftBlob, 0, True);
                   cds.CreateDataSet;

                   repeat
                         cds.Append;
                         cds.FieldByName('ID').AsInteger:=FieldByName('ID').AsInteger;
                         cds.FieldByName('NAME').AsString:=FieldByName('NAME').AsString;
                         cds.FieldByName('PICTURE').Value:=FieldByName('PICTURE').Value;
                         cds.Post;

                         Next;

                   until EOF;

                   cds.MergeChangeLog;

              end;

              Close;
         end;

         result := cds;
    end;


    2. on mobile application function for recive datasource, after connect do DataSnap server, datasource form server is copy to local SQLite database:
      

    function TDataModuleTabeleDanych.SaveDataFormServer: Boolean;
    var
      MyServerMethod: TServerMethods1Client;
      z:TMemoryStream;
      bmp: FMX.Graphics.TBitmap;
    begin
         result:=False;

         if ConnectToDSS=False then Exit;

         MyServerMethod:=DataSnapClientClasses.TServerMethods1Client.Create(DataSnamServerConnection.DBXConnection);

         with MyServerMethod.SendDataFromServer do
         begin
          first;

          repeat

              if FieldByName('ID').AsInteger>0 then
                  begin

                            FDTable.Edit;
                         FDTable.FieldByName('ID').AsInteger:=FieldByName('ID').AsInteger;
                         FDTable.FieldByName('NAME').AsString:=FieldByName('NAME').AsString;

                         z := TMemoryStream.Create;

                         try
                          
                           TBlobField(FieldByName('PICTURE')).SaveToStream(z);

                   z.Position := 0;

                           //picture save to BLOB field in local database
                           TBlobField(FDTable.FieldByName('PICTURE')).LoadFromStream(z);

                           //picture save to file

                           //testinf option for bmp create object 
                           //bmp := FMX.Graphics.TBitmap.Create; // on Android exception: java.lang.IllegalArgumentException: width and height must be > 0
                           //bmp := FMX.Graphics.TBitmap.Create(100, 100); // on Android empty file create on local disk 
                           bmp := FMX.Graphics.TBitmap.CreateFromStream(z); // on Android do nothing, file not create on local disk



                           bmp.LoadFromStream(z);
                           bmp.SaveToFile(FileLocation);


                         finally
                              z.Free;
                         end;

                         FDTable.Post;
                     end;  

             Next;

          until EOF;
         end;

         DisconnectFromDSS;

         result:=True;
    end;


    On WIn32 everything working with any problems

    On Android i Can't save bitmap in database and as file on local android storage

    Anybody help me ;)

    best regards
     
  2. barisatalay
    Offline

    barisatalay DF Senior

    RE:

    I don't test it. I write on mind

    Code:
    var
      MyServerMethod: TServerMethods1Client;
      Z : TMemoryStream;
      ImageOject: TImage
    begin
      Result := False;
      
      if ConnectToDSS=False then Exit; 
      
      MyServerMethod:=DataSnapClientClasses.TServerMethods1Client.Create(DataSnamServe​rConnection.DBXConnection);
      
      with MyServerMethod.SendDataFromServer do
      begin
        first;
    	repeat
    	  if FieldByName('ID').AsInteger>0 then
          begin
    	    FDTable.Edit;
    		FDTable.FieldByName('ID').AsInteger:=FieldByName('ID').AsInteger;
            FDTable.FieldByName('NAME').AsString:=FieldByName('NAME').AsString;
    		Z := TMemoryStream.Create;
    	   	
    		try             
              TBlobField(FieldByName('PICTURE')).SaveToStream(Z);
    		  
    		  TBlobField(FDTable.FieldByName('PICTURE')).LoadFromStream(z); 
    		  
    		  Z.Seek(0,soFromBeginning);
    		  Z.SaveToFile(FileLocation);
    		  
              ImageOject := TImage.Create(Application);
              With ImageOject do
              begin
                Parent     := YourParentObject
                WrapMode   := TImageWrapMode.Stretch;
                Align := TAlignLayout.Client;
    			
                Bitmap.LoadFromFile(FileLocation);
              end;
    		finally
              Z.Free;
            end;
    		FDTable.Post;		
          end;
          Next;
        until EOF;
       end;
      DisconnectFromDSS;
    
      Result := True;
    end;
    
     
  3. realist
    Online

    realistrealist is a Verified Member DelphiFan CoAdmin Staff Member DF Staff

    Thanks
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block