Android 相机拍照,解决拍照过小不清晰
来源:互联网 发布:ubuntu u盘安装 黑屏 编辑:程序博客网 时间:2024/04/29 09:43
布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.takephoto.MainActivity" > <Button android:id="@+id/btn_openCamera" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="click" android:text="openCamera" /> <ImageView android:id="@+id/iv_photo" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_launcher" /></LinearLayout>
全部代码:
package com.example.takephoto;import java.io.File;import java.text.SimpleDateFormat;import java.util.Date;import android.content.Intent;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Matrix;import android.net.Uri;import android.os.Bundle;import android.os.Environment;import android.provider.MediaStore;import android.support.v7.app.ActionBarActivity;import android.util.Log;import android.view.View;import android.widget.ImageView;public class MainActivity extends ActionBarActivity { private String photo_name; private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImageView = (ImageView)findViewById(R.id.iv_photo); } public void click(View view) { switch (view.getId()) { case R.id.btn_openCamera: String currentTime = getCurrentTime(); photo_name = currentTime + ".jpg"; if (isSDAvaiable()) { Log.i("click", "sd可用"); Log.i("click", "开启相机"); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + photo_name))); startActivityForResult(intent, 1); } else { Log.i("click", "sd不可用"); } break; default: break; } } @Override protected void onActivityResult(int arg0, int arg1, Intent arg2) { if (arg0 == 1) { Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + photo_name); Bitmap resizeBitmap = resizeBitmap(bitmap, 640); mImageView.setImageBitmap(resizeBitmap); } super.onActivityResult(arg0, arg1, arg2); } private boolean isSDAvaiable() { String externalStorageState = Environment.getExternalStorageState(); if (externalStorageState.equals(Environment.MEDIA_MOUNTED)) { return true; } else { return false; } } public static Bitmap resizeBitmap(Bitmap bitmap, int newWidth) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float temp = ((float)height) / ((float)width); int newHeight = (int)((newWidth) * temp); float scaleWidth = ((float)newWidth) / width; float scaleHeight = ((float)newHeight) / height; Matrix matrix = new Matrix(); // resize the bit map matrix.postScale(scaleWidth, scaleHeight); // matrix.postRotate(45); Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); bitmap.recycle(); return resizedBitmap; } private String getCurrentTime() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss "); Date curDate = new Date(System.currentTimeMillis()); String timeString = simpleDateFormat.format(curDate); return timeString; }}demo:
网盘资源地址
0 0
- Android 相机拍照,解决拍照过小不清晰
- 解决相机拍照不清晰,拍照旋转问题!
- Android 拍照裁剪图片不清晰解决办法
- 个人心得——相机拍照照片不清晰
- Android 开发调用相机拍照如何获取清晰照片
- android 拍照+裁剪(解决部分相机拍照角度问题)
- Android菜鸟笔记-调用相机拍照后返回照片过小的问题
- 【Android】Android相机拍照
- 调用相机拍照后返回照片过小的问题
- android相机拍照
- android相机拍照源码
- Android中相机拍照
- Android相机拍照,储存
- android相机camera拍照
- android打开相机拍照
- android自定义相机拍照
- Android调用系统相机拍照后不进入预览确认
- Android调用相机拍照返回图片太小
- 分解质因数
- 剑指off-用两个队列模拟栈
- Unity资源之间的关系
- Windows下安装Nginx和PHP
- 如何是cell中的图片只下载一次
- Android 相机拍照,解决拍照过小不清晰
- Java类加载器总结
- Jmeter 通过用户自定义进行参数化
- STM32F0 串口接收超时
- == !=比较的是内存地址 字符串用equals比较
- LayoutInflater和inflate
- Android入门(48)——第三章 数据存储之文件存储
- c#与返回多表的存储过程 dbml
- 剑指off-用两个栈试下你队列