本文介绍了以与Android和显示的元数据的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写一个应用程序,拍照,然后显示其元数据的形象,这是我到目前为止有:
I am writing an app that takes a photo and then displays the image with its metadata, this is what I have so far:
<?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>
这里是我的活动:
And here is my activity:
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和位置以及位置错误,说所有的3不能得到解决。任何想法,我有codeD错了吗?我能做些什么,使这项工作?谢谢!
I am getting an error for imgFile and with location and Location, saying all 3 cannot be resolved. Any idea what I have coded wrong? What can I do to make this work?Thanks!
推荐答案
其实你没有定义imgFile或位置onActivityResult()。
In fact you are not defining imgFile or location in onActivityResult().
另外,你需要导入位置:
Also you need to import Location:
import android.location.Location;
和需要得到一个LocationManager从获得的位置:
And need to get the location from a LocationManager obtained from:
Context.getSystemService(Context.LOCATION_SERVICE);
这篇关于以与Android和显示的元数据的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!