[英]Delphi Firemonkey XE8 - how to correctly send/receive images using DataSnap
I'm developing an Android app using Delphi Firemonkey XE8. 我正在使用Delphi Firemonkey XE8开发一个Android应用程序。 I need to send images to the server, where a service has to receive and store them.
我需要将图像发送到服务器,服务必须在其中接收和存储它们。
So far I was able to send and receive simple classes, like this: 到目前为止,我已经能够发送和接收简单的类,如下所示:
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;
The bitmap images are stored in a SQLite database as BLOB. 位图图像作为BLOB存储在SQLite数据库中。 I need to send those images to the server and, as soon as they get there, save them in the MySQL database, in BLOB fields as well.
我需要将这些图像发送到服务器,并在它们到达服务器后立即将它们保存在MySQL数据库的BLOB字段中。
I need to do it using DataSnap. 我需要使用DataSnap做到这一点。
Everything I tried so far hasn't worked. 到目前为止,我尝试的所有操作均无效。
I resolved the issue in this way: 我以这种方式解决了这个问题:
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;
Maybe not very elegant, but it works. 也许不是很优雅,但是可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.