简体   繁体   English

如何将更新的图像输出到图库?

[英]How to output updated image to gallery?

The exif interface is used in my application to write new data to a stored image,captured using the camera intent in Android. exif接口在我的应用程序中用于将新数据写入存储的图像,该图像是使用Android中的相机意图捕获的。

The problem is when the image file is output to storage, my code for updating the attributes of the image doesn't actually update the stored image when I view details of the image in the gallery. 问题是当图像文件输出到存储设备时,当我在图库中查看图像的details时,我用于更新图像属性的代码实际上并未更新存储的图像。

For example I use the UserComment tag to add some generic text as a test input but this is not displayed in the image's details on the device. 例如,我使用UserComment标记添加了一些常规文本作为测试输入,但是这并没有显示在设备上图像的详细信息中。

My question is, how can I check if the data is actually being written to the file? 我的问题是,如何检查数据是否实际写入文件中?

If I know that the attributes are being appended to the image then I can debug the storage of the file as the problem. 如果我知道属性将被附加到映像,则可以将文件存储调试为问题。

This is the getOutputPhotoFile() method which retrieves the last captured image in the directory of the project: 这是getOutputPhotoFile()方法,该方法检索项目目录中最后捕获的图​​像:

private File getOutputPhotoFile() throws IOException {
          File directory = new File(Environment.getExternalStoragePublicDirectory(
                        Environment.DIRECTORY_PICTURES), getPackageName());
          if (!directory.exists()) {
            if (!directory.mkdirs()) {
              Log.e(TAG, "Failed to create storage directory.");
              return null;
            }
          }


          String timeStamp = new SimpleDateFormat("yyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());

          File[] files = directory.listFiles();

          File origFile =  new File(directory.getPath(), "IMG_" + timeStamp + ".jpg");

          if(files.length!=0) {
              File newestFile = files[files.length-1];
              origFile =  new File(directory.getPath() + File.separator + newestFile.getName());
          }

          String mString = "Generic Text..";     
          ExifInterface exifFile = new ExifInterface(origFile.getAbsolutePath());
          exifFile.setAttribute("UserComment", mString);

          exifFile.setAttribute(ExifInterface.TAG_GPS_LATITUDE,
            String.valueOf(latituteField.toString()));

          exifFile.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, 
            String.valueOf(longitudeField.toString()));

          exifFile.saveAttributes();

      return origFile; 

    }

Upon looking into ExifInterface API , it seems that there is no Exif TAG with the name "UserComment". 在查看ExifInterface API时 ,似乎没有名称为“ UserComment”的Exif TAG。

It seems that it only supports TAGs mentioned in the given API. 似乎它仅支持给定API中提到的TAG。

After setting the location values, you can use same ExifInterface API getAttribute(ExifInterface.TAG_GPS_LATITUDE,) and getAttribute(ExifInterface.TAG_GPS_LONGITUDE) to check whether the file has the values set. 设置位置值后,可以使用相同的ExifInterface API getAttribute(ExifInterface.TAG_GPS_LATITUDE,)getAttribute(ExifInterface.TAG_GPS_LONGITUDE)检查文件是否设置了值。

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

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