我正在使用Delphi Firemonkey XE8开发Android应用程序。我需要将图像发送到服务器,服务必须接收并存储它们。
到目前为止,我能够发送和接收简单的类,如下所示:
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;
位图图像作为BLOB存储在SQLite数据库中。我需要将这些图像发送到服务器,并且一旦到达那里,就将它们保存在MySQL数据库中,也存储在BLOB字段中。
我需要使用DataSnap来实现。
到目前为止我尝试的所有东西都没有用。
答案 0 :(得分:1)
我用这种方式解决了这个问题:
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;
也许不是很优雅,但它有效。