定义一个照相机类CameraOneActivityActivity,这个类中有一个Button一个ImageView
public class CameraOneActivityActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera); Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { String sdStatus = Environment.getExternalStorageState(); // 检测sd是否可用 if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { Log.v("TestFile", "SD card is not avaiable/writeable right now."); return; } Bundle bundle = data.getExtras(); // 获取相机返回的数据,并转换为Bitmap图片格式 Bitmap bitmap = (Bitmap) bundle.get("data"); FileOutputStream b = null; File file = new File("/sdcard/myImage/"); // 创建文件夹 file.mkdirs(); // 将时间命名为照片的名字 String str = null; Date date = null; // 获取当前时间,进一步转化为字符串 SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd-HH-mm-ss"); date = new Date(); str = format.format(date); //以时间的名字保存在SDK下,并且格式为JPG String fileName = "/sdcard/myImage/" + str + ".jpg"; try { b = new FileOutputStream(fileName); // 把数据写入文件 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { b.flush(); b.close(); } catch (IOException e) { e.printStackTrace(); } } // 将图片显示在ImageView里 ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap); } } }
定义界面的camer.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" > <Button android:id="@+id/button" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="点击启动相机" /> <ImageView android:id="@+id/imageView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#999999" /> </LinearLayout>
以上代码就是系统调用一个照相机并将照片赋值给一个ImageView,并将照片保存在Sd卡下
相关推荐
Android调用系统摄像头拍照并显示在ImageView上
通过调用系统的照相机进行拍照,完成拍照后返回原activity并将照片显示在ImageView中 ,再点击保存按钮对照片进行保存
android 将Imageview 将view生成图片后保存到本地相册的实现生成图片后保存到本地相册的实现,android 将Imageview生成图片后保存到本地相册的实现 android 将Imageview生成图片后保存到本地相册的实现, 有需要的朋友...
通过图片的url获取到图片,并显示到imageview中,本实例中选择的图片的百度官网的logo。仅提供一种获取网络图片的方法。
Android中实现调用摄像头拍照并显示在ImageView中示例代码
基于androidStudio开发的App,实现了拍照功能,并能对照片进行剪裁操作,然后回显到imageView控件上。
Android 安卓调用系统相机拍摄照片一例,在打开相机后自动检测sd是否可用,获取相机返回的数据,并转换为Bitmap图片格式,创建文件夹,把数据写入文件,将图片显示在ImageView里。其实是向android新手演示了整个大致...
让两个imageView上的图片实现动画互换并且让互换后的Imageview位置也互换
使用ImageView显示图片很简单,下面的教程在布局文件中直接通过布局属性将图片布局了,so easy的~~教程见:http://www.ourunix.org/android/post/125.html
裁剪图片,通过imageView显示,调用intent
当系统scaleType,显示图片方式满足不了我们时,自定义view显示任意图片指定区域
通过调用系统的相册或者相机,将图片设置到Imageview上面
driveimageview First things first ...The example application is available at the play store: General idea The idea of this android library is to give the possibility to display two texts inside the ...
自定义带边框ImageView
该自定义ImageView除了可以显示png图片,还可以显示gif图片的动画效果
`将源文件解析成Bitmap后再`imageView.setImageBitmap();`的话,图片的方向会发生偏转。 大多数情况下操作图片不可避免的涉及到直接操作Bitmap,所以就需要解决图片旋转问题了,下面是演示如何拍照、选择相册中的...
圆形的ImageView可以完全替代安卓系统默认的ImageView,内附详细demo。
由于是继承于ImageView,且在onDraw()时去掉了super.onDraw(),并覆写了设置drawable的函数,因此可以直接将此view赋值给类似Glide等第三方的库,使其直接加载图片,且图片为圆形(不需要做调整); 支持padding; 多...
一个可以实现从本地图片库读取文件并在imageview显示,还可以实现裁剪功能并显示出来。