ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Android 图片获取显示照片拍摄时间,Android岗面试必问

2022-03-20 13:34:12  阅读:334  来源: 互联网

标签:cursor 必问 uri bitmap listener 面试 date Android null


Canvas canvas = new Canvas(bitmap);

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

// text color - #3D3D3D

paint.setColor(Color.RED);

// text size in pixels

paint.setTextSize(30);

// text shadow

// paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

Rect bounds = new Rect();

paint.getTextBounds(date, 0, date.length(), bounds);

int x = (bitmap.getWidth() - bounds.width());

canvas.drawText(date, x - 10, bitmap.getHeight() - 10, paint);

canvas.save();

return bitmap;

}

2.如果是从图库选择的照片,我们需要先获取照片拍摄日期,然后再将日期画上去,代码如下:

//从图库选择

private void fromGallery(Intent data, OnFilishedListener listener) {

Uri uri = data.getData();

String[] filePathColumn = {MediaStore.Images.Media.DATA , MediaStore.Images.Media.DATE_TAKEN};

Cursor cursor = null;

if (uri == null)

return;

if (uri.getScheme().contains(“file”)) {

Long fileTime = (new File(uri.getPath())).lastModified();

String dateTime = TimeUtil.longToDate1(fileTime);

Log.i(“wtt”,"照片拍摄日期为dateTime: " + dateTime);

saveSelectPic( dateTime , uri.getPath(), listener);

} else if (uri.getScheme().contains(“content”)) {

if (fragment != null) {

curso

r = fragment.getActivity().getContentResolver()

.query(uri, filePathColumn, null, null, null);

} else {

cursor = activity.getContentResolver().

query(uri,filePathColumn, null, null, null);

}

if (cursor.moveToFirst()) {

int columnIndex = cursor.getColumnIndex(filePathColumn[0]);

String picturePath = cursor.getString(columnIndex);

int dateIndex = cursor.getColumnIndexOrThrow(filePathColumn[1]);

String date = cursor.getString(dateIndex);

if (TextUtils.isEmpty(date)) {

date = TimeUtil.getStringDate1();

}else{

date = TimeUtil.longToDate1(Long.parseLong(date));

}

cursor.close();

saveSelectPic(date , picturePath, listener);

} else {

listener.onFilish(null);

}

}

}

/**

  • 保存圖片

  • @param picPath

  • @param listener

*/

private void saveSelectPic(String date, String picPath, OnFilishedListener listener) {

if (TextUtils.isEmpty(picPath)) {

listener.onFilish(null);

return;

}

Bitmap bitmap = BitmapUtils.scaleBitmap(picPath);

bitmap = BitmapUtils.drawDate2Bitmap( date , bitmap);

try {

picPath = BitmapUtils.saveBitmap(bitmap);

listener.onFilish(picPath);

} catch (Exception e) {

e.printStackTrace();

Log.e(“保存图片”, “图片保存失败”);

listener.onFilish(null);

}

}

总结

**其实上面说了这么多,钱是永远赚不完的,在这个知识付费的时代,知识技能提升才是是根本!我作为一名8年的高级工程师,知识技能已经学习的差不多。**在看这篇文章的可能有刚刚入门,刚刚开始工作,或者大佬级人物。

像刚刚开始学Android开发小白想要快速提升自己,最快捷的方式,就是有人可以带着你一起分析,这样学习起来最为高效,所以这里分享一套高手学习的源码和框架视频等精品Android架构师教程,保证你学了以后保证薪资上升一个台阶。

这么重要的事情说三遍啦!点赞+点赞+点赞!

【Android高级架构师系统学习资料】高级架构师进阶必备——设计思想解读开源框架

第一章、热修复设计
第二章、插件化框架设计
第三章、组件化框架设计
第四章、图片加载框架
第五章、网络访问框架设计
第六章、RXJava 响应式编程框架设计
第七章、IOC 架构设计
第八章、Android 架构组件 Jetpack


系统学习资料】高级架构师进阶必备——设计思想解读开源框架

第一章、热修复设计
第二章、插件化框架设计
第三章、组件化框架设计
第四章、图片加载框架
第五章、网络访问框架设计
第六章、RXJava 响应式编程框架设计
第七章、IOC 架构设计
第八章、Android 架构组件 Jetpack

[外链图片转存中…(img-9EPHTABn-1647753719494)]

标签:cursor,必问,uri,bitmap,listener,面试,date,Android,null
来源: https://blog.csdn.net/m0_67735420/article/details/123611487

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有