我在DelphiXE5中内置了一个Android应用程序,该应用程序使用TActionList的StandardActionTTakePhotoFromCameraAction从相机捕获图片:
procedure TF_EdCamara.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
begin
{ Assign the image retrieved from the Camera to the TImage component. }
Image1.Bitmap.Assign(Image);
end;
现在,我需要通过无线将Android的图像存储到Windows PC。
?我如何从DelphiXE5实现这一点?
注意:我的应用程序还使用DataSnap/Rest技术,因此如果需要,我可以利用它
谢谢,
已解决!
服务器端:
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');