Android学习笔记_图片相关
来源:互联网 发布:异形与人类谁厉害 知乎 编辑:程序博客网 时间:2024/05/22 14:02
========图片相关的知识=======
a. 获得手机屏幕的宽高(兼容低版本)
WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
windowHeight = wm.getDefaultDisplay().getHeight();
windowWidth = wm.getDefaultDisplay().getWidth();
b. 加载图片到内存
-- 不是真的解析图片到内存,只是解析图片的宽高等信息
BitmapFactory.Options opt = new Options();
opt.inJustDecodeBounds = true;
BitmapFactory.decodeFile("/sdcard/a.jpg", opt);
--真的解析图片
opt.inJustDecodeBounds = false;
//采样率
opt.inSampleSize = 1;
Bitmap bm = BitmapFactory.decodeFile("/sdcard/a.jpg", opt);
c. 获得图片头部信息
ExifInterface exif = new ExifInterface("/sdcard/a.jpg");
String datetime = exif.getAttribute(ExifInterface.TAG_DATETIME);
String orientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
String make = exif.getAttribute(ExifInterface.TAG_MAKE);
d. 获取系统Gallery的图片
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, 0);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
Uri uri = data.getData();
iv.setImageURI(uri);
}
}
e. 画图
-- 定义画笔
paint = new Paint();
paint.setStrokeWidth(3);
paint.setColor(Color.GRAY);
//创建图片模版
baseBitmap = Bitmap.createBitmap(300, 375, Bitmap.Config.ARGB_8888);
//创建画布
canvas = new Canvas(baseBitmap);
canvas.drawColor(Color.WHITE);
//然后响应ImageView的iv.setOnTouchListener(new OnTouchListener() {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: //finger down
break;
case MotionEvent.ACTION_MOVE: // finger move
break;
case MotionEvent.ACTION_UP: // finger up
break;
});
//最后保存到sdcard
FileOutputStream fos = new FileOutputStream(file);
baseBitmap.compress(CompressFormat.JPEG, 100, fos);
//模拟SD卡挂载媒体的动作,相当于刷新一下,Gallery里才能看到
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MEDIA_MOUNTED);
intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
sendBroadcast(intent);
f. 其他操作
-- decode出来的是只读图片,createBitmap出来的是可更改的
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.g3_back, opts);
-- 可以设置Matrix参数放大,缩小,旋转图片
matrix.setScale(0.5f, 1); //水平方向缩小0.5倍
matrix.setRotate(180, baseBitmap2.getWidth()/2, baseBitmap2.getHeight()/2); //以第二三参数为圆心旋转180度
matrix3.setTranslate(10, 15); //水平和竖直移动
matrix5.setScale(-1, 1); // 获得倒影效果
- Android学习笔记_图片相关
- Android图片相关学习
- Loadrunner学习笔记_内存相关
- Loadrunner学习笔记_磁盘相关
- linux学习笔记3_硬盘分区相关
- Linux学习笔记_安全相关
- Opencv学习笔记_载入显示图片
- OpenCV学习笔记_缩放图片
- OpenCV学习笔记_图片边缘检测
- OpenCV学习笔记_图片融合cvAddWeighted
- Android的ion相关学习_前言
- Android学习笔记---23_网络通信之网络图片查看器
- android学习笔记---48_实现软件国际化,实现文字国际化,和图片国际化
- Android学习笔记 day01 _ Android基础知识
- 笔记_数据库相关
- 黑马程序员--IOS_学习笔记_内存管理相关@porperty
- 0003_分贝db相关的学习笔记_20170324
- Android学习笔记01_走马观花
- Single Sign-On(SSO)单点登陆的具体实现方案
- Ajax表单提交插件jquery form
- Hadoop 0.20.2+Sqoop 1.44+HBase 0.94从MySql往HDFS导入数据报错
- uinput模拟鼠标
- UVa 10550 - Combination Lock
- Android学习笔记_图片相关
- [LeetCode56]Minimum Path Sum
- Cygwin下安装pip无效的问题
- 百度云
- 抽象类理解
- Form表单插件jquery.form.js
- 从控制台中读取密码 - C#
- (Struts2学习篇) Struts2文件处理之文件下载
- 网页设计找灵感——汽车酷站欣赏