如何从Android图库中选择图像并获取路径+ GPS数据(经纬度)?
使用下面的代码,我无法获得包含GPS数据的原始图像的路径。 它返回没有GPS数据的缓存文件的路径。 “ /data/user/0/com.embarcadero.Project1/cache/IMG_20190319_[...].jpg” 原始图像位于“ / DCIM / Camera /”中,并具有另一个名称。
如何从原始图像中获取路径?
procedure TForm2.FormCreate(Sender: TObject);
begin
TMessageManager.DefaultManager.SubscribeToMessage(TMessageReceivedImagePath, DidReceiveBitmap);
end;
procedure TForm2.TakePhotoFromLibraryAction1DidCancelTaking;
begin
//
end;
procedure TForm2.TakePhotoFromLibraryAction1DidFinishTaking(Image: TBitmap);
begin
Image1.Bitmap := Image;
end;
procedure TForm2.DidReceiveBitmap(const Sender: TObject; const M: TMessage);
var
LMessage: TMessageResultNotification;
LImagePath: String;
begin
if M is TMessageReceivedImagePath then
begin
LMessage := TMessageResultNotification(M);
LImagePath := (M as TMessageReceivedImagePath).Value; // <--- '/data/user/0/com.embarcadero.Project1/cache/IMG_20190319_[...].jpg'
if LMessage.RequestCode = TJFMXMediaLibrary.JavaClass.ACTION_TAKE_IMAGE_FROM_LIBRARY then
begin
GetEXIF(LImagePath);
Image2.Bitmap.LoadFromFile(LImagePath);
end;
end;
end;
procedure TForm2.GetEXIF(const AFileName: String);
var
LEXIF: JExifInterface;
LLatLong: TJavaArray<Single>;
begin
LEXIF := TJExifInterface.JavaClass.init(StringToJString(AFileName));
Memo1.Lines.Add('File: ' + AFileName);
LLatLong := TJavaArray<Single>.Create(2);
if LEXIF.getLatLong(LLatLong) then
begin
Memo1.Lines.Add('Latitude: ' + LLatLong.Items[0].ToString);
Memo1.Lines.Add('Longitude: ' + LLatLong.Items[1].ToString);
end;
LLatLong.Free;
end;