use of com.android.gallery3d.exif.ExifTag in project android_packages_apps_Gallery2 by LineageOS.
the class ImageLoader method getExif.
public static List<ExifTag> getExif(Context context, Uri uri) {
String path = getLocalPathFromUri(context, uri);
if (path != null) {
Uri localUri = Uri.parse(path);
String mimeType = getMimeType(localUri);
if (!JPEG_MIME_TYPE.equals(mimeType)) {
return null;
}
try {
ExifInterface exif = new ExifInterface();
exif.readExif(path);
List<ExifTag> taglist = exif.getAllTags();
return taglist;
} catch (IOException e) {
Log.w(LOGTAG, "Failed to read EXIF tags", e);
} catch (NullPointerException e) {
Log.e(LOGTAG, "Failed to read EXIF tags", e);
}
}
return null;
}
use of com.android.gallery3d.exif.ExifTag in project android_packages_apps_Gallery2 by LineageOS.
the class LocalImage method rotate.
@Override
public void rotate(int degrees) {
GalleryUtils.assertNotInRenderThread();
Uri baseUri = Images.Media.EXTERNAL_CONTENT_URI;
ContentValues values = new ContentValues();
int rotation = (this.rotation + degrees) % 360;
if (rotation < 0)
rotation += 360;
if (mimeType.equalsIgnoreCase("image/jpeg")) {
ExifInterface exifInterface = new ExifInterface();
ExifTag tag = exifInterface.buildTag(ExifInterface.TAG_ORIENTATION, ExifInterface.getOrientationValueForRotation(rotation));
if (tag != null) {
exifInterface.setTag(tag);
try {
exifInterface.forceRewriteExif(filePath);
fileSize = new File(filePath).length();
values.put(Images.Media.SIZE, fileSize);
} catch (FileNotFoundException e) {
Log.w(TAG, "cannot find file to set exif: " + filePath);
} catch (IOException e) {
Log.w(TAG, "cannot set exif data: " + filePath);
}
} else {
Log.w(TAG, "Could not build tag: " + ExifInterface.TAG_ORIENTATION);
}
}
values.put(Images.Media.ORIENTATION, rotation);
mApplication.getContentResolver().update(baseUri, values, "_id=?", new String[] { String.valueOf(id) });
}
use of com.android.gallery3d.exif.ExifTag in project android_packages_apps_Gallery2 by LineageOS.
the class InfoPanel method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (getDialog() != null) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
mMainView = (LinearLayout) inflater.inflate(R.layout.filtershow_info_panel, null, false);
mImageThumbnail = (ImageView) mMainView.findViewById(R.id.imageThumbnail);
Bitmap bitmap = MasterImage.getImage().getFilteredImage();
mImageThumbnail.setImageBitmap(bitmap);
mImageName = (TextView) mMainView.findViewById(R.id.imageName);
mImageSize = (TextView) mMainView.findViewById(R.id.imageSize);
mExifData = (TextView) mMainView.findViewById(R.id.exifData);
TextView exifLabel = (TextView) mMainView.findViewById(R.id.exifLabel);
HistogramView histogramView = (HistogramView) mMainView.findViewById(R.id.histogramView);
histogramView.setBitmap(bitmap);
histogramView.setBackgroundColor(Color.DKGRAY);
Uri uri = MasterImage.getImage().getUri();
String path = ImageLoader.getLocalPathFromUri(getActivity(), uri);
Uri localUri = null;
if (path != null) {
localUri = Uri.parse(path);
}
if (localUri != null) {
mImageName.setText(localUri.getLastPathSegment());
}
Rect originalBounds = MasterImage.getImage().getOriginalBounds();
mImageSize.setText("" + originalBounds.width() + " x " + originalBounds.height());
List<ExifTag> exif = MasterImage.getImage().getEXIF();
String exifString = "";
boolean hasExifData = false;
if (exif != null) {
for (ExifTag tag : exif) {
exifString += createStringFromIfFound(tag, ExifInterface.TAG_MODEL, R.string.filtershow_exif_model);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_APERTURE_VALUE, R.string.filtershow_exif_aperture);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_FOCAL_LENGTH, R.string.filtershow_exif_focal_length);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_ISO_SPEED_RATINGS, R.string.filtershow_exif_iso);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_SUBJECT_DISTANCE, R.string.filtershow_exif_subject_distance);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_DATE_TIME_ORIGINAL, R.string.filtershow_exif_date);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_F_NUMBER, R.string.filtershow_exif_f_stop);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_EXPOSURE_TIME, R.string.filtershow_exif_exposure_time);
exifString += createStringFromIfFound(tag, ExifInterface.TAG_COPYRIGHT, R.string.filtershow_exif_copyright);
hasExifData = true;
}
}
if (hasExifData) {
exifLabel.setVisibility(View.VISIBLE);
mExifData.setText(Html.fromHtml(exifString));
} else {
exifLabel.setVisibility(View.GONE);
}
return mMainView;
}
use of com.android.gallery3d.exif.ExifTag in project android_packages_apps_Gallery2 by LineageOS.
the class MediaDetails method extractExifInfo.
public static void extractExifInfo(MediaDetails details, String filePath) {
ExifInterface exif = new ExifInterface();
try {
exif.readExif(filePath);
} catch (FileNotFoundException e) {
Log.w(TAG, "Could not find file to read exif: " + filePath, e);
} catch (IOException e) {
Log.w(TAG, "Could not read exif from file: " + filePath, e);
}
setExifData(details, exif.getTag(ExifInterface.TAG_FLASH), MediaDetails.INDEX_FLASH);
setExifData(details, exif.getTag(ExifInterface.TAG_IMAGE_WIDTH), MediaDetails.INDEX_WIDTH);
setExifData(details, exif.getTag(ExifInterface.TAG_IMAGE_LENGTH), MediaDetails.INDEX_HEIGHT);
ExifTag recordTag = exif.getTag(ExifInterface.TAG_DATE_TIME_ORIGINAL);
if (recordTag == null)
recordTag = exif.getTag(ExifInterface.TAG_DATE_TIME_DIGITIZED);
if (recordTag == null)
recordTag = exif.getTag(ExifInterface.TAG_DATE_TIME);
setExifData(details, recordTag, MediaDetails.INDEX_DATETIME_ORIGINAL);
setExifData(details, exif.getTag(ExifInterface.TAG_MAKE), MediaDetails.INDEX_MAKE);
setExifData(details, exif.getTag(ExifInterface.TAG_MODEL), MediaDetails.INDEX_MODEL);
setExifData(details, exif.getTag(ExifInterface.TAG_APERTURE_VALUE), MediaDetails.INDEX_APERTURE);
setExifData(details, exif.getTag(ExifInterface.TAG_ISO_SPEED_RATINGS), MediaDetails.INDEX_ISO);
setExifData(details, exif.getTag(ExifInterface.TAG_WHITE_BALANCE), MediaDetails.INDEX_WHITE_BALANCE);
setExifData(details, exif.getTag(ExifInterface.TAG_EXPOSURE_TIME), MediaDetails.INDEX_EXPOSURE_TIME);
ExifTag focalTag = exif.getTag(ExifInterface.TAG_FOCAL_LENGTH);
if (focalTag != null) {
details.addDetail(MediaDetails.INDEX_FOCAL_LENGTH, focalTag.getValueAsRational(0).toDouble());
details.setUnit(MediaDetails.INDEX_FOCAL_LENGTH, R.string.unit_mm);
}
}
Aggregations