简体   繁体   English

GPS 文件属性 (FMX)

[英]GPS file properties (FMX)

I can find basic properties of a file with System.IOUtils.TFile like size, date etc. But, i can't figure how to get the GPS coordinates from a JPEG (latitude and longitude) in my C++ Builder FMX app for WIN32.我可以使用System.IOUtils.TFile找到文件的基本属性,如大小、日期等。但是,我无法弄清楚如何在我的 C++ Builder FMX 应用程序中从 JPEG(纬度和经度)获取 GPS 坐标以用于 WIN32。

I can do it with a console application based on this GDI+ example from Microsoft.我可以使用基于 Microsoft 的GDI+ 示例的控制台应用程序来完成。 I just can't figure out how to do this up at System.IOUtils.TFile level.我只是不知道如何在System.IOUtils.TFile级别执行此操作。 I don't want to run a console app to get the GPS data if don't have to.如果不需要,我不想运行控制台应用程序来获取 GPS 数据。

You can open the exif data on your own ... This is my ancient C++/VCL code doing so:您可以自己打开 exif 数据……这是我这样做的古老C++/VCL代码:

AnsiString exif_datetime(AnsiString file)
    {
    AnsiString t="";
    int hnd,adr,siz;
    BYTE *dat;
    hnd=FileOpen(file,fmOpenRead);
    if (hnd<0) return t;
    siz=FileSeek(hnd,0,2);
        FileSeek(hnd,0,0);
    dat=new BYTE[siz];
    if (dat==NULL) { FileClose(hnd); return t; }
    siz=FileRead(hnd,dat,siz);
    FileClose(hnd);

    for (adr=0;adr<siz-4;adr++)
        {
        if (dat[adr+0]=='E')
        if (dat[adr+1]=='x')
        if (dat[adr+2]=='i')
        if (dat[adr+3]=='f')
        if (dat[adr+4]== 0 )    // Exif header found
            {
            for (;adr<siz-18;adr++)
                {
                int e=1;
                char a; // "2008:07:17 19:19:10"
                a=dat[adr+ 0]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 1]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 2]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 3]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 4]; if (a!=':') e=0;
                a=dat[adr+ 5]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 6]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 7]; if (a!=':') e=0;
                a=dat[adr+ 8]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+ 9]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+10]; if (a!=' ') e=0;
                a=dat[adr+11]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+12]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+13]; if (a!=':') e=0;
                a=dat[adr+14]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+15]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+16]; if (a!=':') e=0;
                a=dat[adr+17]; if ((a<'0')||(a>'9')) e=0;
                a=dat[adr+18]; if ((a<'0')||(a>'9')) e=0;
                if (e)
                    {
                    for (e=0;e<19;e++) t+=char(dat[adr+e]);
                    break;
                    }
                }
            break;
            }
        }

    delete[] dat;
    return t;
    }

It opens and loads JPG into memory, scan for EXIF structure and if found return date time from it ...它打开并将JPG加载到内存中,扫描EXIF结构,如果找到则返回日期时间......

So just extract info you want instead ofthe datetime ... on how to do it see:所以只需提取你想要的信息而不是日期时间......关于如何做到这一点,请参阅:

Its the first file format specs I found (from wiki).它是我发现的第一个文件格式规范(来自 wiki)。

In case you got big images the EXIF in JPG is usually placed at the start of file so you do not need to load the whole image to memory just few first (K)Bytes ...如果您有大图像,JPG 中的 EXIF 通常位于文件的开头,因此您无需将整个图像加载到内存中,只需前几个 (K) 字节...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM