2016-04-06 2 views
0

Ich entwickle eine Android App mit Delphi Firemonkey XE8. Ich muss Bilder an den Server senden, wo ein Dienst sie empfangen und speichern muss.Delphi Firefemonkey XE8 - Wie man Bilder mit DataSnap korrekt sendet/empfängt

Bisher war ich in der Lage einfache Klassen zu senden und empfangen, wie folgt aus:

TCliente = class 
     private 
      pCodigo: integer; 
      pNomeRazaoSocial: string; 
      pApelidoFantasia: string; 
      pCPFCNPJ: string; 
     public 
      property Codigo: integer read pCodigo write pCodigo; 
      property NomeRazaoSocial: string read pNomeRazaoSocial write pNomeRazaoSocial; 
      property ApelidoFantasia: string read pApelidoFantasia write pApelidoFantasia; 
      property CPFCNPJ: string read pCPFCNPJ write pCPFCNPJ; 
end; 

Die Bitmap-Bilder werden in einer SQLite-Datenbank als BLOB gespeichert. Ich muss diese Bilder an den Server senden und, sobald sie dort angekommen sind, sie in der MySQL-Datenbank speichern, auch in BLOB-Feldern.

Ich muss es mit DataSnap tun.

Alles, was ich bisher versucht habe, hat nicht funktioniert.

+2

Also, was hast du dann versucht? –

Antwort

1

ich das Problem auf diese Weise gelöst:

var 
    strImagem: TMemoryStream; 
    B: TBitmap; 
begin 
//create TBitmap of correct size 
    B := TBitmap.Create(rectSign.Width div 2, rectSign.Height div 2); 
    B.Clear(TAlphaColorRec.White); 

//move source image to the created TBitmap 
    if B.Canvas.BeginScene then 
    try 
     layoutPhoto.PaintTo(B.Canvas, TRectF.Create(, , B.Width, B.Height)); 
    finally 
     B.Canvas.EndScene; 
    end; 

    try 
//create stream for image 
    strImagem := TMemoryStream.Create; 
//load the TBitmap to it 
    B.SaveToStream(strImagem); 
//return cursor of stream to the beginning 
    strImagem.Position := ; 

    dm.qMDevice.SQL.Text := 'UPDATE Orders SET PHOTO = :PHOTO WHERE ROWID = :RowId'; 
    dm.qMDevice.ParamByName('RowId').AsInteger := SourceROW; 
//load to the query the image from our stream 
    dm.qMDevice.ParamByName('PHOTO').LoadFromStream(strImagem, ftBlob); 
    dm.qMDevice.ExecSQL; 
    dm.qMDevice.Close; 
    except 
    on e: Exception do 
     Toast('Unable to save photo #7702:'#13#10 + e.Message); 
    end; 

//release resources 
    FreeAndNil(B); 
    FreeAndNil(strImagem); 
end; 

Vielleicht nicht sehr elegant, aber es funktioniert.

Verwandte Themen