use of android.media.ExifInterface in project react-native-image-picker by marcshilling.
the class MediaUtils method readExifInterface.
public static ReadExifResult readExifInterface(@NonNull ResponseHelper responseHelper, @NonNull final ImageConfig imageConfig) {
ReadExifResult result;
int currentRotation = 0;
try {
ExifInterface exif = new ExifInterface(imageConfig.original.getAbsolutePath());
// extract lat, long, and timestamp and add to the response
float[] latlng = new float[2];
exif.getLatLong(latlng);
float latitude = latlng[0];
float longitude = latlng[1];
if (latitude != 0f || longitude != 0f) {
responseHelper.putDouble("latitude", latitude);
responseHelper.putDouble("longitude", longitude);
}
final String timestamp = exif.getAttribute(ExifInterface.TAG_DATETIME);
final SimpleDateFormat exifDatetimeFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
final DateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
final String isoFormatString = new StringBuilder(isoFormat.format(exifDatetimeFormat.parse(timestamp))).append("Z").toString();
responseHelper.putString("timestamp", isoFormatString);
} catch (Exception e) {
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
boolean isVertical = true;
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
isVertical = false;
currentRotation = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
isVertical = false;
currentRotation = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
currentRotation = 180;
break;
}
responseHelper.putInt("originalRotation", currentRotation);
responseHelper.putBoolean("isVertical", isVertical);
result = new ReadExifResult(currentRotation, null);
} catch (IOException e) {
e.printStackTrace();
result = new ReadExifResult(currentRotation, e);
}
return result;
}
use of android.media.ExifInterface in project Talon-for-Twitter by klinker24.
the class DirectMessageConversation method getThumbnail.
private Bitmap getThumbnail(Uri uri) throws IOException {
InputStream input = getContentResolver().openInputStream(uri);
int reqWidth = 150;
int reqHeight = 150;
byte[] byteArr = new byte[0];
byte[] buffer = new byte[1024];
int len;
int count = 0;
try {
while ((len = input.read(buffer)) > -1) {
if (len != 0) {
if (count + len > byteArr.length) {
byte[] newbuf = new byte[(count + len) * 2];
System.arraycopy(byteArr, 0, newbuf, 0, count);
byteArr = newbuf;
}
System.arraycopy(buffer, 0, byteArr, count, len);
count += len;
}
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(byteArr, 0, count, options);
options.inSampleSize = Compose.calculateInSampleSize(options, reqWidth, reqHeight);
options.inPurgeable = true;
options.inInputShareable = true;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options);
if (!Compose.isAndroidN()) {
ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
input.close();
b = ImageUtils.cropSquare(b);
return Compose.rotateBitmap(b, orientation);
} else {
input.close();
b = ImageUtils.cropSquare(b);
return b;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of android.media.ExifInterface in project Talon-for-Twitter by klinker24.
the class Compose method getThumbnail.
private Bitmap getThumbnail(Uri uri) throws FileNotFoundException, IOException {
InputStream input = getContentResolver().openInputStream(uri);
int reqWidth = 150;
int reqHeight = 150;
byte[] byteArr = new byte[0];
byte[] buffer = new byte[1024];
int len;
int count = 0;
try {
while ((len = input.read(buffer)) > -1) {
if (len != 0) {
if (count + len > byteArr.length) {
byte[] newbuf = new byte[(count + len) * 2];
System.arraycopy(byteArr, 0, newbuf, 0, count);
byteArr = newbuf;
}
System.arraycopy(buffer, 0, byteArr, count, len);
count += len;
}
}
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(byteArr, 0, count, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inPurgeable = true;
options.inInputShareable = true;
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap b = BitmapFactory.decodeByteArray(byteArr, 0, count, options);
ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
b = ImageUtils.cropSquare(b);
return rotateBitmap(b, orientation);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of android.media.ExifInterface in project Talon-for-Twitter by klinker24.
the class ProfilePager method getBitmapToSend.
private Bitmap getBitmapToSend(Uri uri) throws FileNotFoundException, IOException {
InputStream input = getContentResolver().openInputStream(uri);
BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
onlyBoundsOptions.inJustDecodeBounds = true;
// optional
onlyBoundsOptions.inDither = true;
// optional
onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
input.close();
if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
return null;
int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth;
double ratio = (originalSize > 1000) ? (originalSize / 1000) : 1.0;
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio);
// optional
bitmapOptions.inDither = true;
bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
input = this.getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
ExifInterface exif = new ExifInterface(IOUtils.getPath(uri, context));
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
input.close();
return bitmap;
}
use of android.media.ExifInterface in project ARCamera by escnqh.
the class ShotActivity method try2Shot.
public void try2Shot(Mat mRgbaT, Mat mGrayT) {
final long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - nowtime > 1000 && FLAG < 21) {
Log.i("Time Logggggggggg", currentTimeMillis + "");
nowtime = currentTimeMillis;
FLAG++;
Mat mBgr = new Mat();
final String photoPath = albumPath + File.separator + currentTimeMillis + ".jpg";
final ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, photoPath);
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg");
values.put(MediaStore.Images.Media.TITLE, appName);
values.put(MediaStore.Images.Media.DESCRIPTION, appName);
values.put(MediaStore.Images.Media.DATE_TAKEN, currentTimeMillis);
// Ensure that the album directory exists.
File album = new File(albumPath);
if (!album.isDirectory() && !album.mkdirs()) {
Log.e(TAG, "Failed to create album directory at " + albumPath);
}
// Try to create the photo.
Imgproc.cvtColor(mRgbaT, mBgr, Imgproc.COLOR_RGBA2BGR, 3);
if (!Imgcodecs.imwrite(photoPath, mBgr)) {
Log.e(TAG, "Failed to save photo to " + photoPath);
}
Log.d(TAG, "Photo saved successfully to " + photoPath);
// Try to insert the photo into the MediaStore.
Uri uri;
try {
uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (final Exception e) {
Log.e(TAG, "Failed to insert photo into MediaStore");
e.printStackTrace();
// Since the insertion failed, delete the photo.
File photo = new File(photoPath);
if (!photo.delete()) {
Log.e(TAG, "Failed to delete non-inserted photo");
}
}
try {
ExifInterface exif = new ExifInterface(photoPath);
exif.setAttribute(ExifInterface.TAG_MAKE, "ShotByPeelson");
exif.setAttribute(ExifInterface.TAG_MODEL, "ShotByPeelson");
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations