Search in sources :

Example 76 with ExifInterface

use of android.media.ExifInterface in project PhotoNoter by yydcdut.

the class DetailPresenterImpl method getExifInformation.

private String getExifInformation(String path) throws IOException {
    String enter = "\n";
    StringBuilder sb = new StringBuilder();
    ExifInterface exifInterface = new ExifInterface(path);
    String fDateTime = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
    sb.append(mContext.getResources().getString(R.string.detail_dateTime)).append(checkExifData(fDateTime)).append(enter);
    String fOrientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION);
    if (fOrientation.equals(String.valueOf(ExifInterface.ORIENTATION_NORMAL))) {
        fOrientation = "0";
    } else if (fOrientation.equals(String.valueOf(ExifInterface.ORIENTATION_ROTATE_90))) {
        fOrientation = "90";
    } else if (fOrientation.equals(String.valueOf(ExifInterface.ORIENTATION_ROTATE_270))) {
        fOrientation = "270";
    } else if (fOrientation.equals(String.valueOf(ExifInterface.ORIENTATION_ROTATE_180))) {
        fOrientation = "180";
    } else if (fOrientation.equals(String.valueOf(ExifInterface.ORIENTATION_ROTATE_270 | ExifInterface.ORIENTATION_FLIP_HORIZONTAL))) {
        fOrientation = "270";
    } else {
        fOrientation = mContext.getResources().getString(R.string.detail_unknown);
    }
    sb.append(mContext.getResources().getString(R.string.detail_orientation)).append(fOrientation).append(enter);
    String fFlash = exifInterface.getAttribute(ExifInterface.TAG_FLASH);
    sb.append(mContext.getResources().getString(R.string.detail_flash)).append((TextUtils.isEmpty(fFlash) || "0".equals(fFlash) || "null".equals(fFlash)) ? mContext.getResources().getString(R.string.detail_flash_close) : mContext.getResources().getString(R.string.detail_flash_open)).append(enter);
    String fImageWidth = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
    if (TextUtils.isEmpty(fImageWidth) || "0".equals(fImageWidth) || "null".equals(fImageWidth)) {
        int[] size = FilePathUtils.getPictureSize(path);
        sb.append(mContext.getResources().getString(R.string.detail_image_width)).append(size[0]).append(enter);
        sb.append(mContext.getResources().getString(R.string.detail_image_length)).append(size[1]).append(enter);
    } else {
        sb.append(mContext.getResources().getString(R.string.detail_image_width)).append(fImageWidth).append(enter);
        String fImageLength = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
        sb.append(mContext.getResources().getString(R.string.detail_image_length)).append(fImageLength).append(enter);
    }
    String fWhiteBalance = exifInterface.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
    sb.append(mContext.getResources().getString(R.string.detail_white_balance)).append((TextUtils.isEmpty(fImageWidth) || "0".equals(fWhiteBalance) || "null".equals(fImageWidth.toLowerCase())) ? mContext.getResources().getString(R.string.detail_wb_auto) : mContext.getResources().getString(R.string.detail_wb_manual)).append(enter);
    String longitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    if (TextUtils.isEmpty(longitude) || "null".equals(longitude.toLowerCase())) {
        sb.append(mContext.getResources().getString(R.string.detail_longitude)).append(mContext.getResources().getString(R.string.detail_unknown)).append(enter);
        sb.append(mContext.getResources().getString(R.string.detail_latitude)).append(mContext.getResources().getString(R.string.detail_unknown)).append(enter);
    } else {
        String[] longitudeSs = longitude.split(",");
        double longitudesD = 0;
        longitudesD += Double.parseDouble(longitudeSs[0].split("/")[0]);
        longitudesD += (((int) (Double.parseDouble(longitudeSs[1].split("/")[0]) * 100)) + Double.parseDouble(longitudeSs[2].split("/")[0]) / 60 / 10000) / 60 / 100;
        sb.append(mContext.getResources().getString(R.string.detail_longitude)).append(longitudesD + "").append(enter);
        String latitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
        String[] latitudeSs = latitude.split(",");
        double latitudesD = 0;
        latitudesD += Double.parseDouble(latitudeSs[0].split("/")[0]);
        latitudesD += (((int) (Double.parseDouble(latitudeSs[1].split("/")[0]) * 100)) + Double.parseDouble(latitudeSs[2].split("/")[0]) / 60 / 10000) / 60 / 100;
        sb.append(mContext.getResources().getString(R.string.detail_latitude)).append(latitudesD + "").append(enter);
    }
    String fMake = exifInterface.getAttribute(ExifInterface.TAG_MAKE);
    sb.append(mContext.getResources().getString(R.string.detail_make)).append(checkExifData(fMake)).append(enter);
    String fModel = exifInterface.getAttribute(ExifInterface.TAG_MODEL);
    sb.append(mContext.getResources().getString(R.string.detail_model)).append(checkExifData(fModel)).append(enter);
    String fAperture = exifInterface.getAttribute(ExifInterface.TAG_APERTURE);
    sb.append(mContext.getResources().getString(R.string.detail_aperture)).append(checkExifData(fAperture)).append(enter);
    String fExposureTime = exifInterface.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
    sb.append(mContext.getResources().getString(R.string.detail_exposure_time)).append(checkExifData(fExposureTime)).append(enter);
    String fFocalLength = exifInterface.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
    sb.append(mContext.getResources().getString(R.string.detail_focal_length)).append(checkExifData(fFocalLength)).append(enter);
    String fISOSpeedRatings = exifInterface.getAttribute(ExifInterface.TAG_ISO);
    sb.append(mContext.getResources().getString(R.string.detail_iso)).append(checkExifData(fISOSpeedRatings)).append(enter);
    return sb.toString();
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ExifInterface(android.media.ExifInterface)

Example 77 with ExifInterface

use of android.media.ExifInterface in project PhotoNoter by yydcdut.

the class MapPresenterImpl method gps.

private void gps(String path) throws IOException {
    ExifInterface exifInterface = new ExifInterface(path);
    String longitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    if (longitude != null && !"null".equals(longitude.toLowerCase())) {
        String[] longitudeSs = longitude.split(",");
        double longitudesD = 0;
        longitudesD += Double.parseDouble(longitudeSs[0].split("/")[0]);
        longitudesD += (((int) (Double.parseDouble(longitudeSs[1].split("/")[0]) * 100)) + Double.parseDouble(longitudeSs[2].split("/")[0]) / 60 / 10000) / 60 / 100;
        String latitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
        String[] latitudeSs = latitude.split(",");
        double latitudesD = 0;
        latitudesD += Double.parseDouble(latitudeSs[0].split("/")[0]);
        latitudesD += (((int) (Double.parseDouble(latitudeSs[1].split("/")[0]) * 100)) + Double.parseDouble(latitudeSs[2].split("/")[0]) / 60 / 10000) / 60 / 100;
        doGps(latitudesD, longitudesD);
    }
}
Also used : ExifInterface(android.media.ExifInterface)

Example 78 with ExifInterface

use of android.media.ExifInterface in project xabber-android by redsolution.

the class ImageCompressor method compressImage.

public static File compressImage(final File file, String outputDirectory) {
    String path = file.getPath();
    String format = path.substring(path.lastIndexOf(".")).substring(1);
    Bitmap source;
    try {
        source = decodeFile(file, MAX_SIZE_PIXELS, MAX_SIZE_PIXELS);
    } catch (Exception e) {
        Log.d(ImageCompressor.class.toString(), e.toString());
        return null;
    }
    Bitmap.CompressFormat compressFormat;
    // if png pr webp have allowed resolution then not compress it
    if ("png".equals(format) || "webp".equals(format))
        return file;
    // select format
    switch(format) {
        case "png":
            compressFormat = Bitmap.CompressFormat.PNG;
            break;
        case "webp":
            compressFormat = Bitmap.CompressFormat.WEBP;
            break;
        case "gif":
            return file;
        default:
            compressFormat = Bitmap.CompressFormat.JPEG;
    }
    // resize image
    Bitmap resizedBmp;
    if (source.getHeight() > MAX_SIZE_PIXELS || source.getWidth() > MAX_SIZE_PIXELS) {
        resizedBmp = resizeBitmap(source, MAX_SIZE_PIXELS);
    } else {
        resizedBmp = source;
    }
    // create directory if not exist
    File directory = new File(outputDirectory);
    directory.mkdirs();
    // compress image
    File result = new File(outputDirectory, file.getName());
    FileOutputStream fOut;
    try {
        fOut = new FileOutputStream(result);
        resizedBmp.compress(compressFormat, IMAGE_QUALITY, fOut);
        fOut.flush();
        fOut.close();
        source.recycle();
        resizedBmp.recycle();
    } catch (Exception e) {
        return null;
    }
    // copy EXIF orientation from original image
    try {
        ExifInterface oldExif = new ExifInterface(file.getPath());
        String exifOrientation = oldExif.getAttribute(ExifInterface.TAG_ORIENTATION);
        if (exifOrientation != null) {
            ExifInterface newExif = new ExifInterface(result.getPath());
            newExif.setAttribute(ExifInterface.TAG_ORIENTATION, exifOrientation);
            newExif.saveAttributes();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
Also used : Bitmap(android.graphics.Bitmap) FileOutputStream(java.io.FileOutputStream) ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 79 with ExifInterface

use of android.media.ExifInterface in project ImagePicker by jeasonlzy.

the class BitmapUtil method getBitmapDegree.

/**
 * 获取图片的旋转角度
 *
 * @param path 图片绝对路径
 * @return 图片的旋转角度
 */
public static int getBitmapDegree(String path) {
    int degree = 0;
    try {
        // 从指定路径下读取图片,并获取其EXIF信息
        ExifInterface exifInterface = new ExifInterface(path);
        // 获取图片的旋转信息
        int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        switch(orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                degree = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                degree = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                degree = 270;
                break;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return degree;
}
Also used : ExifInterface(android.media.ExifInterface) IOException(java.io.IOException)

Example 80 with ExifInterface

use of android.media.ExifInterface in project LshUtils by SenhLinsh.

the class ImageUtilsEx method saveExif.

/**
 * 将 srcFilePath 图片文件的 Exif 信息保存到 destFilePath 图片文件中
 *
 * @param srcFilePath  保存有 Exif 信息的图片文件
 * @param destFilePath 需要保存 Exif 信息的图片文件
 */
public static void saveExif(String srcFilePath, String destFilePath) throws Exception {
    ExifInterface oldExif = new ExifInterface(srcFilePath);
    ExifInterface newExif = new ExifInterface(destFilePath);
    Class<ExifInterface> cls = ExifInterface.class;
    Field[] fields = cls.getFields();
    for (int i = 0; i < fields.length; i++) {
        String fieldName = fields[i].getName();
        if (!TextUtils.isEmpty(fieldName) && fieldName.startsWith("TAG")) {
            String fieldValue = fields[i].get(cls).toString();
            String attribute = oldExif.getAttribute(fieldValue);
            if (attribute != null) {
                newExif.setAttribute(fieldValue, attribute);
            }
        }
    }
    newExif.saveAttributes();
}
Also used : Field(java.lang.reflect.Field) ExifInterface(android.media.ExifInterface)

Aggregations

ExifInterface (android.media.ExifInterface)153 IOException (java.io.IOException)93 Paint (android.graphics.Paint)32 Bitmap (android.graphics.Bitmap)26 InputStream (java.io.InputStream)21 File (java.io.File)17 BitmapFactory (android.graphics.BitmapFactory)16 Matrix (android.graphics.Matrix)15 FileInputStream (java.io.FileInputStream)15 Point (android.graphics.Point)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ErrnoException (android.system.ErrnoException)10 BufferedInputStream (java.io.BufferedInputStream)10 FileDescriptor (java.io.FileDescriptor)10 FileNotFoundException (java.io.FileNotFoundException)10 SuppressLint (android.annotation.SuppressLint)9 FileOutputStream (java.io.FileOutputStream)8 Cursor (android.database.Cursor)7 AssetFileDescriptor (android.content.res.AssetFileDescriptor)6 Bundle (android.os.Bundle)5