关于拍照,相册 取照片
来源:互联网 发布:郭富城 小美 知乎 编辑:程序博客网 时间:2024/05/01 16:09
由于项目着急,总是拷贝代码,实现功能就行了,很少思考。闲着无聊就看了下代码。。
SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory()+ File.separator + "llkj" + File.separator + "my"+ File.separator + "ysh-" + "commodity" + ".jpg";String state = Environment.getExternalStorageState();if (state.equals(Environment.MEDIA_MOUNTED)) {file = new File(SD_CARD_TEMP_DIR);file.delete();if (!file.exists()) {try {file.createNewFile();} catch (IOException e) {e.printStackTrace();Toast.makeText(this, "照片创建失败!", Toast.LENGTH_LONG).show();return;}}Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));startActivityForResult(intent, 4);
BitmapFactory.Options option = new BitmapFactory.Options();<span style="white-space:pre"></span>option.inSampleSize = 2;<span style="white-space:pre"></span>Bitmap photo = BitmapFactory.decodeFile(f.getPath(), option);//为什么要用路径呢,就是把拍照的照片存放到指定的路径,然后根据路径直接去取出来就行了。就这么简单。
if (data != null) {Bitmap photo = null;String[] projection;File f = null;Bundle extras = data.getExtras();if (null != extras) {photo = (Bitmap) extras.get("data");} else {Uri uri = data.getData();if (uri != null) {projection = new String[] { MediaColumns.DATA };Cursor cursor = managedQuery(uri, projection, null,null, null);int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA);System.out.println("706-------------camera------"+ column_index);cursor.moveToFirst();String uploadPhotPath = cursor.getString(column_index);System.out.println("camera--------------------561----------- 相册图片的地址--------"+ uploadPhotPath);BitmapFactory.Options option = new BitmapFactory.Options();option.inSampleSize = 2;photo = BitmapFactory.decodeFile(uploadPhotPath, option);}}
//相册读取照片,就是返回uri根据uri找到照片就ok
不管拍照或者相册取出的照片剪切,返回的是bitmap直接用就行了
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); photoPickerIntent.putExtra("crop", "true"); photoPickerIntent.putExtra("aspectX", 1); photoPickerIntent.putExtra("aspectY", 1); photoPickerIntent.putExtra("outputX", 96); photoPickerIntent.putExtra("outputY", 96); photoPickerIntent.putExtra("return-data", true); startActivityForResult(photoPickerIntent, 3);
Intent cropIntent = new Intent("com.android.camera.action.CROP"); cropIntent.setDataAndType(Uri.fromFile(f), "image/*"); cropIntent.putExtra("crop", "true"); cropIntent.putExtra("aspectX", 1); cropIntent.putExtra("aspectY", 1); cropIntent.putExtra("outputX", 96); cropIntent.putExtra("outputY", 96); cropIntent.putExtra("return-data", true); startActivityForResult(cropIntent, 3);
case 3: if (data != null) { final Bitmap photo = data.getParcelableExtra("data"); if (photo == null) return; dialog = ProgressDialog.show(this, "", "正在上传", true, true); // 调用上传头像接口 // uploadFile.uploadImg(getApplicationContext(), photo); }
0 0
- 关于拍照,相册 取照片
- 拍照后压缩、 在相册中选取照片
- Android拍照或从相册中取照片
- 相机拍照,相册照片
- UIImagePickerController 相册取照片
- 获取相册照片和获取拍照照片
- 拍照和从相册中选取照片,并保存到SD卡上
- Android完美满足你所有的拍照或从相册中选取照片
- android 选择照片(相册/拍照/切图)
- Android拍照或相册获取照片上传
- Android 从相册选择照片 手机拍照
- Android 拍照和从相册选照片
- Android 中拍照、相册选择、裁剪照片
- Android开发之获取相册照片和获取拍照照片
- Android:获取相册照片和获取拍照照片
- Android开发之获取相册照片和获取拍照照片
- Android开发之获取相册照片和获取拍照照片
- Android开发之获取相册照片和获取拍照照片
- debug 记录(1)
- jxl创建Excel文件java代码示例
- #ifdef-#endif的作用及其使用技巧
- [索引] Volume 2. Data Structures
- POJ 1384 Piggy-Bank 背包DP
- 关于拍照,相册 取照片
- 栈和队列的简单讲解和函数用法
- Unix Domain Protocols
- css盒模型笔记
- 研磨Hadoop源码(六)ResourceManager启动分析2
- listview的listSelector在android2.3和2.2上的bug
- 数组
- UITableView的重用机制
- ShareSDK 微信分享注意的问题