Firemonkey TBitmap em TBytes TakePhotoFromCameraAction1DidFinishTaking
23/03/2020
0
Tenho uma função que envia arquivos para o AWS S3
preciso pegar a imagem capturada no TakePhotoFromCameraAction1DidFinishTaking e transformar em Byte para enviar mais não sei por onde começar.
function TF_Cadsuspeito.UploadFile(pFile: TBytes; FileName, Bucket: string): boolean;
var
Service: TAmazonStorageService;
ConAmazon: TAmazonConnectionInfo;
begin
try
ConAmazon := TAmazonConnectionInfo.Create(nil);
ConAmazon.AccountKey := SecretKey;
ConAmazon.AccountName := AccessKey;
ConAmazon.QueueEndpoint := 'queue.amazonaws.com';
ConAmazon.StorageEndpoint := 's3-us-east-1.amazonaws.com';
ConAmazon.TableEndpoint := 'sdb.amazonaws.com';
ConAmazon.UseDefaultEndpoints := False;
Service := TAmazonStorageService.Create(ConAmazon);
Result := Service.UploadObject(Bucket, FileName, pFile, TRUE, nil, nil, amzbaPrivate, nil);
finally
ConAmazon.Free;
Service.Free;
end;
end;
preciso pegar a imagem capturada no TakePhotoFromCameraAction1DidFinishTaking e transformar em Byte para enviar mais não sei por onde começar.
function TF_Cadsuspeito.UploadFile(pFile: TBytes; FileName, Bucket: string): boolean;
var
Service: TAmazonStorageService;
ConAmazon: TAmazonConnectionInfo;
begin
try
ConAmazon := TAmazonConnectionInfo.Create(nil);
ConAmazon.AccountKey := SecretKey;
ConAmazon.AccountName := AccessKey;
ConAmazon.QueueEndpoint := 'queue.amazonaws.com';
ConAmazon.StorageEndpoint := 's3-us-east-1.amazonaws.com';
ConAmazon.TableEndpoint := 'sdb.amazonaws.com';
ConAmazon.UseDefaultEndpoints := False;
Service := TAmazonStorageService.Create(ConAmazon);
Result := Service.UploadObject(Bucket, FileName, pFile, TRUE, nil, nil, amzbaPrivate, nil);
finally
ConAmazon.Free;
Service.Free;
end;
end;
Inarais Jerônimo
Curtir tópico
+ 0
Responder
Posts
24/03/2020
Inarais Jerônimo
Tenho uma função que envia arquivos para o AWS S3
preciso pegar a imagem capturada no TakePhotoFromCameraAction1DidFinishTaking e transformar em Byte para enviar mais não sei por onde começar.
function TF_Cadsuspeito.UploadFile(pFile: TBytes; FileName, Bucket: string): boolean;
var
Service: TAmazonStorageService;
ConAmazon: TAmazonConnectionInfo;
begin
try
ConAmazon := TAmazonConnectionInfo.Create(nil);
ConAmazon.AccountKey := SecretKey;
ConAmazon.AccountName := AccessKey;
ConAmazon.QueueEndpoint := 'queue.amazonaws.com';
ConAmazon.StorageEndpoint := 's3-us-east-1.amazonaws.com';
ConAmazon.TableEndpoint := 'sdb.amazonaws.com';
ConAmazon.UseDefaultEndpoints := False;
Service := TAmazonStorageService.Create(ConAmazon);
Result := Service.UploadObject(Bucket, FileName, pFile, TRUE, nil, nil, amzbaPrivate, nil);
finally
ConAmazon.Free;
Service.Free;
end;
end;
preciso pegar a imagem capturada no TakePhotoFromCameraAction1DidFinishTaking e transformar em Byte para enviar mais não sei por onde começar.
function TF_Cadsuspeito.UploadFile(pFile: TBytes; FileName, Bucket: string): boolean;
var
Service: TAmazonStorageService;
ConAmazon: TAmazonConnectionInfo;
begin
try
ConAmazon := TAmazonConnectionInfo.Create(nil);
ConAmazon.AccountKey := SecretKey;
ConAmazon.AccountName := AccessKey;
ConAmazon.QueueEndpoint := 'queue.amazonaws.com';
ConAmazon.StorageEndpoint := 's3-us-east-1.amazonaws.com';
ConAmazon.TableEndpoint := 'sdb.amazonaws.com';
ConAmazon.UseDefaultEndpoints := False;
Service := TAmazonStorageService.Create(ConAmazon);
Result := Service.UploadObject(Bucket, FileName, pFile, TRUE, nil, nil, amzbaPrivate, nil);
finally
ConAmazon.Free;
Service.Free;
end;
end;
A solução foi criar um memorystream do Tbitmap isso pode ser feito de duas formas:
Bitmap.SaveToStream(Image_Stream);
procedure BitmapToStream( aBitmap: TBitmap; aStream: TStream ); var MS: TMemoryStream; S: int32; begin MS := TMemoryStream.Create; try aBitmap.SaveToStream(MS); MS.Position := 0; if MS.Size>MaxInt then begin raise Exception.Create('TSpriteSheet.BitmapToStream: Image data too large.'); end; S := MS.Size; aStream.Write(S,Sizeof(S)); MS.SaveToStream(aStream); finally MS.Free; end; end;
ao final minha rotina ficou assim
procedure BitmapToStream( aBitmap: TBitmap; aStream: TStream ); var MS: TMemoryStream; S: int32; begin MS := TMemoryStream.Create; try aBitmap.SaveToStream(MS); MS.Position := 0; if MS.Size>MaxInt then begin raise Exception.Create('TSpriteSheet.BitmapToStream: Image data too large.'); end; S := MS.Size; aStream.Write(S,Sizeof(S)); MS.SaveToStream(aStream); finally MS.Free; end; end; procedure UploadImage(); var // ConAmazon: TAmazonConnectionInfo; Service: TAmazonStorageService; regions:TAmazonRegion; Response: TCloudResponseInfo; Image_Byte: TBytes; Image_Stream: TMemoryStream; bResult : Boolean; begin try Image_Stream:= TMemoryStream.Create; //Form1.Image1.MultiResBitmap.Items[0].Bitmap.SaveToStream(Image_Stream); //Image_Stream:= TFileStream.Create('C:\\Users\\sinho\\OneDrive\\Imagens\\teste.jpg', 0); BitmapToStream(Form1.Image1.MultiResBitmap.Items[0].Bitmap,Image_Stream); SetLength(Image_Byte, Image_Stream.Size); Image_Stream.Position := 0; Image_Stream.Read(Image_Byte, Image_Stream.Size ); Form1.ConAmazon := TAmazonConnectionInfo.Create(nil); Form1.ConAmazon.AccountKey := 'LRxxxxxxxxxxxxxxxxxxxx'; Form1.ConAmazon.AccountName := 'AKIxxxxxxxxxxxxxxxxx'; Form1.ConAmazon.Region:= TAmazonRegion.amzrUSEast1 ; Form1.ConAmazon.QueueEndpoint := 'queue.amazonaws.com'; Form1.ConAmazon.TableEndpoint := 'sdb.amazonaws.com'; Service := TAmazonStorageService.Create(Form1.ConAmazon); Response := TCloudResponseInfo.Create; bResult:= Service.UploadObject('romobr', 'teste.jpg', Image_Byte, False, nil, nil, amzbaPrivate, Response, regions); if bResult = True then ShowMessage('Upload success'+#13+IntToStr(Response.StatusCode)+' -> ' + Response.StatusMessage) else ShowMessage('Upload fails'+#13+IntToStr(Response.StatusCode)+' -> ' + Response.StatusMessage) Finally Image_Stream.Free; Service.Free; Form1.ConAmazon.Free; end; end;
Responder
Clique aqui para fazer login e interagir na Comunidade :)