用android拍照并显示元数据

用android拍照并显示元数据,第1张

概述我正在编写一个应用程序,该应用程序先拍照,然后显示带有元数据的图像,这就是我到目前为止的内容:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"android:orientation="vertical"

我正在编写一个应用程序,该应用程序先拍照,然后显示带有元数据的图像,这就是我到目前为止的内容:

    <?xml version="1.0" enCoding="utf-8"?>    <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"       androID:orIEntation="vertical"       androID:layout_wIDth="fill_parent"       androID:layout_height="fill_parent">        <button            androID:ID="@+ID/button1"            androID:layout_wIDth="fill_parent"            androID:layout_height="wrap_content"            androID:text="@string/openCamera" />        <ImageVIEw            androID:src="@androID:drawable/ic_menu_gallery"            androID:layout_wIDth="fill_parent"            androID:layout_height="300.0dp"            androID:ID="@+ID/imageVIEw1"            androID:adjustVIEwBounds="true" />        </linearLayout>

这是我的活动:

    import java.io.file;    import java.io.fileOutputStream;    import java.io.IOException;    import java.util.Calendar;    import androID.app.Activity;    import androID.content.Intent;    import androID.graphics.Bitmap;    import androID.graphics.BitmapFactory;    import androID.graphics.Camera;    import androID.graphics.Matrix;    import androID.media.ExifInterface;    import androID.os.Bundle;    import androID.util.Log;    import androID.vIEw.SurfaceHolder;    import androID.vIEw.VIEw;    import androID.Widget.button;    import androID.Widget.ImageVIEw;    public class MainActivity extends Activity {        private static final int CAMERA_REQUEST = 1888;         private ImageVIEw imageVIEw;        @OverrIDe        public voID onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentVIEw(R.layout.activity_main);            this.imageVIEw = (ImageVIEw)this.findVIEwByID(R.ID.imageVIEw1);            button photobutton = (button) this.findVIEwByID(R.ID.button1);            photobutton.setonClickListener(new VIEw.OnClickListener() {                @OverrIDe                public voID onClick(VIEw v) {                    Intent cameraIntent = new              Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE);             startActivityForResult(cameraIntent, CAMERA_REQUEST);         }    });}protected voID onActivityResult(int requestCode, int resultCode, Intent data) {      if (requestCode == CAMERA_REQUEST && resultCode == RESulT_OK) {          Bitmap photo = (Bitmap) data.getExtras().get("data");         imageVIEw.setimageBitmap(photo);    }    ExifInterface exif = new ExifInterface(imgfile.getCanonicalPath());    //String latitudeStr = "90/1,12/1,30/1";    double lat = location.getLatitude();    double alat = Math.abs(lat);    String dms = Location.convert(alat, Location.FORMAT_SECONDS);    String[] splits = dms.split(":");    String[] secnds = (splits[2]).split("\.");    String seconds;    if(secnds.length==0)    {        seconds = splits[2];    }    else    {        seconds = secnds[0];    }    String latitudeStr = splits[0] + "/1," + splits[1] + "/1," + seconds + "/1";    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitudeStr);    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, lat>0?"N":"S");    double lon = location.getLongitude();    double alon = Math.abs(lon);    dms = Location.convert(alon, Location.FORMAT_SECONDS);    splits = dms.split(":");    secnds = (splits[2]).split("\.");    if(secnds.length==0)    {        seconds = splits[2];    }    else    {        seconds = secnds[0];    }    String longitudeStr = splits[0] + "/1," + splits[1] + "/1," + seconds + "/1";    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitudeStr);    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, lon>0?"E":"W");    exif.saveAttributes();}            ExifInterface exif = new ExifInterface(imgfile.getCanonicalPath());            //String latitudeStr = "90/1,12/1,30/1";            double lat = location.getLatitude();            double alat = Math.abs(lat);            String dms = Location.convert(alat, Location.FORMAT_SECONDS);            String[] splits = dms.split(":");            String[] secnds = (splits[2]).split("\.");            String seconds;            if(secnds.length==0)            {                seconds = splits[2];            }            else            {                seconds = secnds[0];            }            String latitudeStr = splits[0] + "/1," + splits[1] + "/1," + seconds + "/1";            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitudeStr);            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, lat>0?"N":"S");            double lon = location.getLongitude();            double alon = Math.abs(lon);            dms = Location.convert(alon, Location.FORMAT_SECONDS);            splits = dms.split(":");            secnds = (splits[2]).split("\.");            if(secnds.length==0)            {                seconds = splits[2];            }            else            {                seconds = secnds[0];            }            String longitudeStr = splits[0] + "/1," + splits[1] + "/1," + seconds + "/1";            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitudeStr);            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, lon>0?"E":"W");            exif.saveAttributes();        }    }  

我收到imgfile的错误,并显示了location和Location,说无法解决所有3个问题.知道我的编码有误吗?我该怎么做才能使这项工作?
谢谢!

解决方法:

实际上,您不是在onActivityResult()中定义imgfile或位置.

另外,您需要导入位置:

import androID.location.Location;

并且需要从LocationManager获取位置,该LocationManager是从以下位置获得的:

Context.getSystemService(Context.LOCATION_SERVICE);
总结

以上是内存溢出为你收集整理的用android拍照并显示元数据全部内容,希望文章能够帮你解决用android拍照并显示元数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1093428.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存