我有一个 Android 应用程序内置 DelphiXE5 ,它使用 TTakePhotoFromCameraAction 的从相机中捕获图片强> TActionList :
procedure TF_EdCamara.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
begin
{ Assign the image retrieved from the Camera to the TImage component. }
Image1.Bitmap.Assign(Image);
end;
现在,我需要通过无线将图像 图像存储到 Windows PC 。
¿我如何从 DelphiXE5 实现这一目标?
注意:我的应用也使用 DataSnap / Rest 技术,因此我可以在必要时利用它
谢谢,
答案 0 :(得分:0)
解决!
服务器端:
function TServerMethods.UploadImage(FileName: String; Stream: TStream): Integer;
const
BufSize = $F000;
var
Mem: TMemoryStream;
BytesRead: Integer;
Buffer: PByte;
begin
try
Mem := TMemoryStream.Create;
GetMem(Buffer, BufSize);
try
repeat
BytesRead := Stream.Read(Buffer^, BufSize);
if BytesRead > 0 then
Mem.WriteBuffer(Buffer^, BytesRead);
until BytesRead < BufSize;
// here, replace with DB update (if you want to save to DB)
// for now, save to file
Mem.Seek(0, TseekOrigin.soBeginning); // necessary?
Mem.SaveToFile(FileName); //saves to current dir, you can have a parameter for expected directory otuput
// ============================
Result := 1; // Mem.Size doesn't work...
finally
FreeMem(Buffer, BufSize);
Mem.Free;
end;
except
Result := -1
end;
end;
客户端:
procedure TClientModule.UploadBitmapByStream(Image: TBitmap; FileName: String);
var
ImageStream: TMemoryStream;
Bytes: Integer;
FileName: String;
begin
ImageStream := TMemoryStream.Create;
try
Image.SaveToStream(ImageStream);
ImageStream.Position := 0;
Bytes:= ServerMethods.UploadImage(FileName, ImageStream);
if Bytes = -1 then
raise Exception.create('Image transfer failed!')
finally
ImageStream.Free
end;
end;
然后你可以打电话
ClientModule.UploadBitmapByStream(Image1.Bitmap, 'File001.png');