1

I have captured a picture using the phone camera and stored it in variable "photo"

Bitmap photo = (Bitmap) data.getExtras().get("data"); 

I have also obtained the latitude and longitude using the phone gps

lat = location.getLatitude();
lon = location.getLongitude();

How do I incorporate this gps data in the image only?

P.S. GPS tagged images can be captured manually by enabling the GPS tag option in the camera settings by the user. I want to make sure that the image captured is compulsorily GPS tagged.

2 Answers2

2

you can't set it to the Bitmap, the Bitmap is just a byte array with the image pixels. You have to apply those coordinates after you save it to a file that supports Metadata (for example PNG or JPG)

To do that you use the ExifInterface

Code is similar to that:

String filePath = Enviroment.getExternalStorageDirectory() + "/MyApp/photo.png";
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
photo.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
ExifInterface exif = new ExifInterface(filePath);

// call this next setAttributes a few times to write all the GPS data to it.
exif.setAttribute(... );

// don't forget to save
exif.saveAttributes();
Budius
  • 39,391
  • 16
  • 102
  • 144
0

Is this the what you are looking for?

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109