不否认努力,继续加油!
学习整理重点、盲区,笔记如下:干干巴巴,麻麻赖赖,一点都不圆润……
day06
内容
1. 用户头像的圆形显示
-
实现从本地图库或打开相机拍照获取图片,并设置为圆形;实例已上传GiHhub:LoadCameraMap.
-
Bitmap 和 ImageView 相互转化:精简·Bitmap转换成ImageView和ImageView转换成Bitmap.
-
提供 BitmapUtil.java 实现对 bitmap 的压缩和圆形化处理:
public static Bitmap circleBitmap(Bitmap source) { int width = source.getWidth(); Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); canvas.drawCircle(width / 2, width / 2, width / 2, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(source, 0, 0, paint); return bitmap; } //设置宽高必须使用浮点型,否则导致压缩的比例:0 public static Bitmap zoom(Bitmap source,float width ,float height){ Matrix matrix = new Matrix(); //图片的压缩处理;matrix 是矩阵 matrix.postScale(width / source.getWidth(),height / source.getHeight()); Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false); return bitmap; }
-
调用系统拍照、图库选择图片(已上传GitHub)
-
将头像保存到本地,以便之后调用
private void saveImage(Bitmap bitmap) { File filesDir; //判断sd卡是否挂载 if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { filesDir = this.getExternalFilesDir(""); } else {//手机内部存储 filesDir = this.getFilesDir(); } FileOutputStream fos = null; try { File file = new File(filesDir, "icon.png"); fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } }
-
读取本地保存的 头像,注意方法写在 onResume() 中,不过不删除其父类的 super 方法,注意其生命周期
private boolean readImage() { File filesDir; //判断sd卡是否挂载 if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ filesDir = this.getActivity().getExternalFilesDir(""); }else{//手机内部存储 filesDir = this.getActivity().getFilesDir(); } File file = new File(filesDir,"icon.png"); if(file.exists()){ //存储--->内存 Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath()); ivMeIcon.setImageBitmap(bitmap); return true; } return false; }
2. 支付宝集成
- 最好看最新的文档,有时签约失效,无法实现。
盲区
- 声明:本博客根据尚硅谷项目实战: 硅谷金融.学习整理;
- 关于调用相册的 intent;
Intent intent = new Intent("android.intent.action.GET_CONTENT");
写错后,出现 BUG ,有数据,有路径,但是设置不到 ImageView 中,排查 BUG 又花费了一个上午。 - 关于支付宝集成一直没有成功;
其他笔记
金融App
- 金融APP01—页面架构.
- 金融APP02—主页及工具类创建
- 金融APP03—自定义 MyScrollView & 联网加载数据的4种状态的抽取及代码优化
- 金融APP04—投资理财页面实现
- 金融APP05—随机飞入飞出&流式布局自定义View的使用
商城
Android项目实战—— 商城APP.
新闻
Android项目实战—— 新闻APP.