本文整理汇总了Java中android.media.ExifInterface.saveAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java ExifInterface.saveAttributes方法的具体用法?Java ExifInterface.saveAttributes怎么用?Java ExifInterface.saveAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.ExifInterface
的用法示例。
在下文中一共展示了ExifInterface.saveAttributes方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotate
import android.media.ExifInterface; //导入方法依赖的package包/类
@Override
public void rotate(int degrees) throws Exception {
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(filePath);
exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION,
String.valueOf(rotation));
exifInterface.saveAttributes();
fileSize = new File(filePath).length();
values.put(Images.Media.SIZE, fileSize);
}
values.put(Images.Media.ORIENTATION, rotation);
mApplication.getContentResolver().update(baseUri, values, "_id=?",
new String[]{String.valueOf(id)});
}
示例2: copyExif
import android.media.ExifInterface; //导入方法依赖的package包/类
private static void copyExif(Context context, Uri oldImage, File newFile) throws IOException {
File oldFile = getFileFromUri(context, oldImage);
if (oldFile == null) {
FLog.w(ReactConstants.TAG, "Couldn't get real path for uri: " + oldImage);
return;
}
ExifInterface oldExif = new ExifInterface(oldFile.getAbsolutePath());
ExifInterface newExif = new ExifInterface(newFile.getAbsolutePath());
for (String attribute : EXIF_ATTRIBUTES) {
String value = oldExif.getAttribute(attribute);
if (value != null) {
newExif.setAttribute(attribute, value);
}
}
newExif.saveAttributes();
}
示例3: copyExifRotation
import android.media.ExifInterface; //导入方法依赖的package包/类
public static boolean copyExifRotation(File sourceFile, File destFile) {
if (sourceFile == null || destFile == null) return false;
try {
ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
exifDest.saveAttributes();
return true;
} catch (IOException e) {
return false;
}
}
示例4: copyExifRotation
import android.media.ExifInterface; //导入方法依赖的package包/类
public static boolean copyExifRotation(File sourceFile, File destFile) {
if (sourceFile == null || destFile == null) return false;
try {
ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
exifDest.saveAttributes();
return true;
} catch (IOException e) {
Log.e("Error copying Exif data", e);
return false;
}
}
示例5: copyExifRotation
import android.media.ExifInterface; //导入方法依赖的package包/类
public static boolean copyExifRotation(File sourceFile, File destFile) {
if (sourceFile == null || destFile == null) return false;
try {
ExifInterface exifSource = new ExifInterface(sourceFile.getAbsolutePath());
ExifInterface exifDest = new ExifInterface(destFile.getAbsolutePath());
exifDest.setAttribute(ExifInterface.TAG_ORIENTATION, exifSource.getAttribute(ExifInterface.TAG_ORIENTATION));
exifDest.saveAttributes();
return true;
} catch (IOException e) {
Log.e("Error copying Exif data", String.valueOf(e));
return false;
}
}
示例6: setPictureDegreeZero
import android.media.ExifInterface; //导入方法依赖的package包/类
/**
* 设置图片旋转角度
*
* @param path 路径
* @param rotate 角度
*/
public static void setPictureDegreeZero(String path, int rotate) {
try {
ExifInterface exifInterface = new ExifInterface(path);
//修正图片的旋转角度,设置其不旋转。这里也可以设置其旋转的角度,可以传值过去,
//例如旋转90度,传值ExifInterface.ORIENTATION_ROTATE_90,需要将这个值转换为String类型的
exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, String
.valueOf(rotate));
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: savaPicExif
import android.media.ExifInterface; //导入方法依赖的package包/类
public static void savaPicExif(Context context, String fileName) {
try {
ExifInterface exifInterface = new ExifInterface(fileName);
exifInterface.setAttribute(ExifInterface.TAG_DATETIME, System.currentTimeMillis() + "");
// if (CommonUtil.checkNetState(context) && BaseActivity.location != null && BaseActivity.location.getLatitude() != 0 && BaseActivity.location.getLongitude() != 0) {
// exifInterface.setAttribute(ExifInterface.TAG_GPS_LATITUDE, BaseActivity.location.getLatitude() + "");
// exifInterface.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, BaseActivity.location.getLongitude() + "");
// }
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: setImageOrientation
import android.media.ExifInterface; //导入方法依赖的package包/类
public static void setImageOrientation(File file, int orientation) {
if (file != null) {
try {
ExifInterface exifInterface = new ExifInterface(file.getPath());
String orientationValue = String.valueOf(getOrientationExifValue(orientation));
exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION, orientationValue);
exifInterface.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例9: setExifOrientation
import android.media.ExifInterface; //导入方法依赖的package包/类
public static boolean setExifOrientation(String path, int orientation) {
try {
ExifInterface exif = new ExifInterface(path);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, getExifOrientation(orientation));
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
示例10: writeDataToFile
import android.media.ExifInterface; //导入方法依赖的package包/类
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
fos.close();
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
// copy original exif data to the output exif...
// unfortunately, this Android ExifInterface class doesn't understand all the tags so we lose some
for (Directory directory : originalImageMetaData().getDirectories()) {
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
Object object = directory.getObject(tagType);
exif.setAttribute(tag.getTagName(), object.toString());
}
}
writeLocationExifData(options, exif);
if(hasBeenReoriented)
rewriteOrientation(exif);
exif.saveAttributes();
} catch (ImageProcessingException | IOException e) {
Log.e(TAG, "failed to save exif data", e);
}
}
示例11: copyExif
import android.media.ExifInterface; //导入方法依赖的package包/类
public static void copyExif(ExifInterface originalExif, int width, int height, String imageOutputPath) {
String[] attributes = new String[]{
ExifInterface.TAG_APERTURE,
ExifInterface.TAG_DATETIME,
ExifInterface.TAG_DATETIME_DIGITIZED,
ExifInterface.TAG_EXPOSURE_TIME,
ExifInterface.TAG_FLASH,
ExifInterface.TAG_FOCAL_LENGTH,
ExifInterface.TAG_GPS_ALTITUDE,
ExifInterface.TAG_GPS_ALTITUDE_REF,
ExifInterface.TAG_GPS_DATESTAMP,
ExifInterface.TAG_GPS_LATITUDE,
ExifInterface.TAG_GPS_LATITUDE_REF,
ExifInterface.TAG_GPS_LONGITUDE,
ExifInterface.TAG_GPS_LONGITUDE_REF,
ExifInterface.TAG_GPS_PROCESSING_METHOD,
ExifInterface.TAG_GPS_TIMESTAMP,
ExifInterface.TAG_ISO,
ExifInterface.TAG_MAKE,
ExifInterface.TAG_MODEL,
ExifInterface.TAG_SUBSEC_TIME,
ExifInterface.TAG_SUBSEC_TIME_DIG,
ExifInterface.TAG_SUBSEC_TIME_ORIG,
ExifInterface.TAG_WHITE_BALANCE
};
try {
ExifInterface newExif = new ExifInterface(imageOutputPath);
String value;
for (String attribute : attributes) {
value = originalExif.getAttribute(attribute);
if (!TextUtils.isEmpty(value)) {
newExif.setAttribute(attribute, value);
}
}
newExif.setAttribute(ExifInterface.TAG_IMAGE_WIDTH, String.valueOf(width));
newExif.setAttribute(ExifInterface.TAG_IMAGE_LENGTH, String.valueOf(height));
newExif.setAttribute(ExifInterface.TAG_ORIENTATION, "0");
newExif.saveAttributes();
} catch (IOException e) {
Log.d(TAG, e.getMessage());
}
}
示例12: saveImageWithQuality
import android.media.ExifInterface; //导入方法依赖的package包/类
private File saveImageWithQuality(Bitmap image, int quality, String rotation)
{
File savedImage = getNewImageLocation();
try
{
if (savedImage == null)
{
throw new IOException("Could not create location for image file");
}
boolean created = savedImage.createNewFile();
if (created == false)
{
throw new IOException("Could not create empty image file");
}
FileOutputStream fOut = new FileOutputStream(savedImage);
boolean fileWritten = image.compress(Bitmap.CompressFormat.JPEG, quality, fOut);
fOut.flush();
fOut.close();
if (fileWritten == false)
{
throw new IOException("Could not down compress file");
}
ExifInterface exifData = new ExifInterface(savedImage.getAbsolutePath());
exifData.setAttribute(ExifInterface.TAG_ORIENTATION, rotation);
exifData.saveAttributes();
Log.i(TAG, "Image file " + savedImage.getAbsolutePath() + " saved at quality " + quality + " and rotation " + rotation);
return savedImage;
}
catch(IOException e)
{
Log.e(TAG, "Failed to encode image", e);
Toast.makeText(this, R.string.pictureCaptureError, Toast.LENGTH_LONG).show();
if(savedImage != null)
{
boolean result = savedImage.delete();
if(result == false)
{
Log.w(TAG, "Failed to delete image file: " + savedImage.getAbsolutePath());
}
}
}
return null;
}
示例13: writeDataToFile
import android.media.ExifInterface; //导入方法依赖的package包/类
public void writeDataToFile(File file, ReadableMap options, int jpegQualityPercent) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
fos.write(toJpeg(currentRepresentation, jpegQualityPercent));
fos.close();
try {
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
// copy original exif data to the output exif...
// unfortunately, this Android ExifInterface class doesn't understand all the tags so we lose some
for (Directory directory : originalImageMetaData().getDirectories()) {
for (Tag tag : directory.getTags()) {
int tagType = tag.getTagType();
Object object = directory.getObject(tagType);
exif.setAttribute(tag.getTagName(), object.toString());
}
}
writeLocationExifData(options, exif);
if(hasBeenReoriented)
rewriteOrientation(exif);
exif.saveAttributes();
} catch (ImageProcessingException | IOException e) {
Log.e(TAG, "failed to save exif data", e);
}
}