这次我主要实现调用照相机并且能够在自己设置Activity
上显示此图片,比且当我们照完图片的时候自己可以对照片进行裁剪。
配置文件没有做出改动关键是我们代码的实现,调用手机自带的照相系统,这个最重要的一点就是Intent
的设置就是下面俩句话:
Intent intent=new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
xml文件内布局的设置:
<?xml
version="1.0"
encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="测试"
android:id="@+id/test"
/>
<ImageView
android:id="@+id/iv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
></ImageView>
</LinearLayout>
点击测试之后我们进入系统自带的照相机的那个界面,然后根据情况可以裁减界面,裁剪这块是参考别的书籍上所写的:
下面是主代码:
public
class MainActivity
extends Activity {
private
Button button;
private
ImageView imageView;
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.button=(Button)findViewById(R.id.test);
this.imageView=(ImageView)findViewById(R.id.iv01);
button.setOnClickListener(new
OnClickListener()
{
@Override
public
void onClick(View v)
{
//
TODO Auto-generated method stub\
//设置跳动页面
调用系统自带的照相机
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
}
});
}
//开始处理相片
前段显示图片在onActivityResult中处理返回的data
@Override
protected
void onActivityResult(int
requestCode, int resultCode, Intent data)
{
//
TODO Auto-generated method stub
if(resultCode!=RESULT_OK)
return;
switch (requestCode)
{
//开始对我们完成的Intent乞求开始做出判断
case 1:
Bitmap bitmap = data.getParcelableExtra("data");
if (bitmap!=null)
{
dealBitmap(bitmap);
}
case 0:
Bitmap bitmap2 = data.getParcelableExtra("data");
if(bitmap2!=null){
//显示在我们的Activity上
imageView.setImageBitmap(bitmap2);
}
break;
}
super.onActivityResult(requestCode, resultCode,
data);
}
//开始对我们照完的照片进行处理
protected
void dealBitmap(Bitmap bitmap){
//调用下面的函数开始对图片进行修改
Intent intent = getDealImageIntent(bitmap);
startActivityForResult(intent, 0);
}
public
static Intent getDealImageIntent(Bitmap bitmap)
{
Intent intent = new Intent("com.android.camera.action.CROP");
//设置裁时的一些参数
intent.setType("image/*");
intent.putExtra("data", bitmap);
intent.putExtra("crop",
"true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 128);
intent.putExtra("outputY", 128);
intent.putExtra("return-data",
true);
return intent;
}
}
总体来说难度并不是很大但关键是我们调用照相机之后的处理,以及我们对
Intent使用一些技巧!
分享到:
相关推荐
android照相机应用源码,可以直接运行
android 照相机 demo android 照相机 demo android 照相机 demo android 照相机 demo android 照相机 demo android 照相机 demo
Android4.0.3系统照相机源码。
Android照相机触屏对焦例子
android 照相机源码 Camera源码
Android照相机自动对焦例子
android4.0照相机源码camera源码
Android 照相机 移动对焦
在本篇文章中,我们将探讨如何在 Delphi XE5 中使用 Android 平台的照相机组件,获取拍摄的照片。 使用 Delphi XE5 调用 Android 照相机的步骤 ----------------------------------- 要使用 Delphi XE5 调用 ...
自定义Android照相机,实现只拍摄矩形区域.完美解决预览及拍照时的照片拉伸失真,旋转等问题
android 照相机 源代码 android 照相机 源代码 android 照相机 源代码 (请注意:模拟器不具备照相机功能,只能用真机测试)
Android 照相机裁切图片 像QQ上传图片那样,调用照相机拍照,然后可以手动截取图片区域,放大缩小* 效果见源码
android实现照相机的基本功能有两种 一种是直接在定义照相机 还有一种就是调用内置的相机 个人偏向于后者 因为定义 一个照相机比较复杂 而且效果不是很好这里提供了两个例子
Android源码——调用系统相册和系统照相机功能雨实例源码.zip
Android 录像照相机录像录音
android 照相机 自动对焦
1.android获取本地图片; 2.android系统照相机,拍照保存,获取图片。
Android 应用项目开发源码 参考和学习使用
Android照相机开发,调用系统的照相机进行开发的
android 调用照相机拍照,其中对对焦进行了一定的优化