This article has participated in the good article call order activity, click to see: back end, big front end double track submission, 20,000 yuan prize pool for you to challenge!

preface

In recent work, I encountered some scenes of image processing, mainly extracting some image width, resolution, physical focal length and other information in batch. Then you can see that the pictures contain a lot of other useful information as you use them. This article will share this tip with you.

code

Let’s break it down into a few steps and look at the code implementation.

  • Analysis of images

First, introduce a JAR package

 <dependency>
     <groupId>com.drewnoakes</groupId>
     <artifactId>metadata-extractor</artifactId>
     <version>2.16.0</version>
 </dependency>
Copy the code

Then write a method to get the details of the picture, including when the photo was taken, location information, phone model, and so on.

// Analyze the image to get the address
public static  Map<String,String> PicAnalysis(String path) throws JpegProcessingException, 		IOException {
    Map<String,String> map = new HashMap();
    System.out.println("Powerful language is recognizing picture address...");
    File picFile = new File(path);
    Metadata metadata = JpegMetadataReader.readMetadata(picFile);
    Iterator<Directory> it = metadata.getDirectories().iterator();
    while (it.hasNext()) {
        Directory exif = it.next();
        Iterator<Tag> tags = exif.getTags().iterator();
        while (tags.hasNext()) {
            Tag tag = tags.next();
            map.put(tag.getTagName(),tag.getDescription());
            System.out.println(tag.getTagName() + ":" +tag.getDescription());
        }
    }
    System.out.println("Picture analysis done!");
    return map;
}
Copy the code

This method returns the following information, quite a bit, which is tabulated here:

parameter instructions
Make Product manufacturer
Model Equipment model
Orientation The direction of
X Resolution/Y Resolution X/Y resolution
ResolutionUnit Resolution unit
DateTime Date and Time
Software Software version
ISO speed ratings iso
Date/Time Original Creation time
Date/Time Digitized Digital time
Components Configuration Image construction (mainly refers to the color combination scheme)
Compressed Bits Per Pixel The color bit per pixel in compression refers to the degree of compression
Exposure Bias Value Exposure compensation
Max Aperture Value The largest aperture
Metering Mode Metering mode, average metering, central key metering, point metering, etc
Flash Whether to use flash
Focal Length Focal length, generally display the physical focal length of the lens
Makernote Author mark, note, record
Color Space Color gamut, color space
Exif Image Width Image width, the number of horizontal pixels
Exif Image Height Image height, refers to the number of vertical pixels
  • Convert to coordinates

The information taken from the picture is in degree minute second format: i.e. 30° 14′ 32.52″, we need to convert it to longitude and latitude: e.g. 121.485559,31.240778, code as follows:

public static String translate(String Gps) {
    String a = Gps.split("°") [0].replace(""."");
    String b = Gps.split("°") [1].split("'") [0].replace(""."");
    String c = Gps.split("°") [1].split("'") [1].replace(""."").replace("\" "."");
    double gps = Double.parseDouble(a)+Double.parseDouble(b)/60 + Double.parseDouble(c)/60/60;
    return String.valueOf(gps);
}
Copy the code
  • Unveiling the final veil

After obtaining the specific coordinates, which is only half a step away from success, the next step is to call the Amap Api to obtain the specific address.

 public static void getAddress( Map<String,String> param){
        String str = RequestUtils.sendGet("https://restapi.amap.com/v3/geocode/regeo"."key=5a3c45fd68d04bbc&location="+translate(param.get("GPS Longitude")) +","+translate(param.get("GPS Latitude")));
        JSONObject result = JSON.parseObject(str);
        System.out.println("Time of shooting:" +param.get("Date/Time"));
        System.out.println("Location:" +result.getJSONObject("regeocode").getString("formatted_address"));
        System.out.println("Phone model:" +param.get("Make") +"" + param.get("Model"));
        System.out.println(str);
    }
Copy the code

However, we need to enter the Developer platform of Amap first, and those who do not apply for individual developer status need to apply first. The application procedure is relatively simple. After application, there will be a specified number of free calls every day, which is enough for personal use.

Lazy people play

If you think it is too troublesome and don’t want to apply for developer, ah, just play, just don’t want to apply, then spend Gie also has manual version.

  • Manually convert latitude and longitude

Open the website www.minigps.net/fc.html, you can convert degrees into longitude and latitude online.

  • Manual positioning coordinates

Open the pick coordinate system, input the latitude and longitude obtained in the previous step, you can view the specific address

Git address

You can upload your project to Git at github.com/zsh57753173…

The last

Finally clarify, two dogs so far single, which have what bad mind, and how can there be a girlfriend, this story is purely fictional, if there are similar, EMmm….. See you later.

Pay attention to avoid getting lost

That’s all for this episode. If you have any mistakes, please leave a comment. Thank you very much. I’m Flower Gie, feel free to leave a comment if you have any questions, and we’ll see you next time at 🦮.

The article continues to be updated, can be wechat search Java development zero to one first time to read, and can obtain interview materials learning videos, interested partners welcome attention, study together, ha 🐮🥃.

Original is not easy, how can you bear white whore. if you think this article is a little useful to you, thank you for the old iron for this article point a like, comment or forward, because this will be my power to output more quality articles, thank you!