1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| package com.zalex.exifinterfacedemo;
import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.media.ExifInterface; import android.os.Bundle; import android.os.Environment; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.widget.ImageView; import android.widget.Toast;
public class MainActivity extends AppCompatActivity { String path = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera/IMG_20160927_135402.jpg"; private String width; private String height; private Bitmap bitmap; private Bitmap imgTemp;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView iv= (ImageView) findViewById(R.id.imageview); bitmap = BitmapFactory.decodeFile(path); try { ExifInterface exifInterface=new ExifInterface(path); exifInterface.saveAttributes(); String orientation = exifInterface.getAttribute(ExifInterface.TAG_ORIENTATION); String dateTime = exifInterface.getAttribute(ExifInterface.TAG_DATETIME); String make = exifInterface.getAttribute(ExifInterface.TAG_MAKE); String model = exifInterface.getAttribute(ExifInterface.TAG_MODEL); String flash = exifInterface.getAttribute(ExifInterface.TAG_FLASH); height = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_LENGTH); width = exifInterface.getAttribute(ExifInterface.TAG_IMAGE_WIDTH); String latitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE); String longitude = exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); StringBuilder sb = new StringBuilder(); sb.append(longitude) .append(latitude);
Log.e("TAG", "## orientation=" + orientation); Log.e("TAG", "## dateTime=" + dateTime); Log.e("TAG", "## make=" + make); Log.e("TAG", "## model=" + model); Log.e("TAG", "## flash=" + flash); Log.e("TAG", "## imageLength=" + height); Log.e("TAG", "## imageWidth=" + width); Log.e("TAG", "## latitude=" + latitude); Log.e("TAG", "## longitude=" + longitude); String driving_name="驾校名称:东方时尚驾校"; String coach="教练员姓名:张三"; String lerner="学员姓名:李四"; String time="采集时间:2016"; String car_number="车牌号:京RF8900786"; String longt="102.00"; String lat="35.5"; String car_speed="车辆行驶速度:20km/h";
Toast.makeText(MainActivity.this,sb, Toast.LENGTH_LONG).show(); Drawable drawable = createDrawable(driving_name,coach,lerner,time,car_number,longt,lat,car_speed); iv.setBackgroundDrawable(drawable);
} catch (Exception e) { e.printStackTrace(); }
}
private Drawable createDrawable(String driving_name, String coach, String lerner, String time, String car_number, String longt, String lat, String car_speed) { imgTemp = Bitmap.createBitmap(Integer.valueOf(width), Integer.valueOf(height), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(imgTemp); Paint paint = new Paint(); paint.setDither(true); paint.setFilterBitmap(true); Rect src = new Rect(0, 0,Integer.valueOf(width), Integer.valueOf(height)); Rect dst = new Rect(0, 0, Integer.valueOf(width), Integer.valueOf(height)); canvas.drawBitmap(bitmap, src, dst, paint);
Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); textPaint.setTextSize(100.0f); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setColor(Color.WHITE);
canvas.drawText(driving_name,Integer.valueOf(width)/100, Integer.valueOf(height)/8, textPaint); canvas.drawText(coach,0, (Integer.valueOf(height)/8)+100,textPaint); canvas.drawText(lerner,0,(Integer.valueOf(height)/8)+200,textPaint); canvas.drawText(time,0,(Integer.valueOf(height)/8)+300,textPaint); canvas.drawText(car_number,0,(Integer.valueOf(height)/8)+400,textPaint); canvas.drawText(longt,0,(Integer.valueOf(height)/8)+500,textPaint); canvas.drawText(lat,0,(Integer.valueOf(height)/8)+600,textPaint); canvas.drawText(car_speed,0,(Integer.valueOf(height)/8)+700,textPaint); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore();
return (Drawable) new BitmapDrawable(getResources(), imgTemp);
} }
|