如何解决unsupportedOperationException exifinterface仅支持以jpeg格式保存属性

时间:2018-12-06 10:13:53

标签: android

运行此代码时,它将引发异常,即unsupportedOperationException exifinterface支持以jpeg格式保存属性。

此代码可在Redmi Note 5专业版Android 8.1.0上运行,但不能在Redmi 3S Android 6.0.1版上运行(引发异常)

private void setCamera(double latitude, double longitude) {
                // Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
                //startActivity(intent);
                Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
                String NOMEDIA=".nomedia";
        //folder stuff
                File imagesFolder = new File(Environment.getExternalStorageDirectory(), "LandRecordImages/");
                if(imagesFolder.exists() == false){
                    imagesFolder.mkdirs();
                }
                f = new File(imagesFolder, "lrd_" + timeStamp + ".jpg");
                Uri uriSavedImage = FileProvider.getUriForFile(getApplicationContext(),
                        BuildConfig.APPLICATION_ID + ".provider",
                        f);
                imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                //  uriSavedImage = Uri.fromFile(f);
                mCapturedImagePath  = f.getAbsolutePath();
                // cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/SApp/")));
                startActivityForResult(imageIntent, 1001);
                System.out.println("filename= "+f.getAbsolutePath());
                geoTag(f.getAbsolutePath(), latitude, longitude);

            }

这是函数定义gepTag()

 public void geoTag(String filename, double latitude, double longitude){
            ExifInterface exif;

            try {
                exif = new ExifInterface(filename);
                int num1Lat = (int)Math.floor(latitude);
                int num2Lat = (int)Math.floor((latitude - num1Lat) * 60);
                double num3Lat = (latitude - ((double)num1Lat+((double)num2Lat/60))) * 3600000;

                int num1Lon = (int)Math.floor(longitude);
                int num2Lon = (int)Math.floor((longitude - num1Lon) * 60);
                double num3Lon = (longitude - ((double)num1Lon+((double)num2Lon/60))) * 3600000;

                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, num1Lat+"/1,"+num2Lat+"/1,"+num3Lat+"/1000");
                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, num1Lon+"/1,"+num2Lon+"/1,"+num3Lon+"/1000");


                if (latitude > 0) {
                    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N");
                } else {
                    exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "S");
                }

                if (longitude > 0) {
                    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E");
                } else {
                    exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "W");
                }

                exif.saveAttributes();
            } catch (IOException e) {
                Log.e("PictureActivity", e.getLocalizedMessage());
            }

        }

有人可以解释如何解决此问题吗?

谢谢!

0 个答案:

没有答案