首页 > 其他 > 详细

把相片的详情列表里显示的时间与文件名和标题里指示的时间统一

时间:2015-12-25 02:10:03      阅读:200      评论:0      收藏:0      [点我收藏+]

?

  1. 在Exif这个类中添加方法以取得exif中的时间(照片详情里显示的时间)

    public static String getTime(byte[] jpegData) {
            if (jpegData == null)
                return null;
            ExifInterface exif = getExif(jpegData);
            return exif.getTagStringValue(ExifInterface.TAG_DATE_TIME);
        }
    ?
  2. 在FileSaver类中的PhotoOperator类中调用Exif::getTime方法取得的值经过转换赋值给mDateTaken(涌来生成文件名以及title的)
                String dateTime = Exif.getTime(mData);
                if (null != dateTime) {
                    mDateTaken = stringToLong(dateTime);
                }
    注意要加保护,因为在某些模式下的多张合成照片不是每张都能在exif中取得值;并且注意在

    mTitle = createName(mFileType, mDateTaken, mGroupIndex);
    ?这句之前赋值。
  3. 在PhotoOperator类里面添加方法转换字符串至long型

?

private long stringToLong (String dateTime) {
            Log.d(TAG, "Brandon, the date time string is "+ dateTime);
            // eg. cut the string from 2015:12:24 10:01:52\C0\80 to 2015:12:24 10:01:52
            dateTime = dateTime.substring(0, 19);
            SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
            Log.d(TAG, "Brandon, the cutted string is " + dateTime);
            try {
                Date date = format.parse(dateTime);
                return date.getTime();
            } catch(ParseException e) {
                Log.e(TAG, "[stringToLong] ParseException: " + e);
                return 0;
            }
        }

?其中那个时间格式是从android相片的exif中取得的,要用substring截取第0个index到第19(不包括19)个。

注意Date的parse方法必须放在try...catch对里。

需要

import java.text.SimpleDateFormat;
import java.text.ParseException;

?

?

把相片的详情列表里显示的时间与文件名和标题里指示的时间统一

原文:http://phoobobo.iteye.com/blog/2266324

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!