Android 拍照功能代碼
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Hide the window title. requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.main); imageView = (ImageView) this.findViewById(R.id.iv1); Button button = (Button) this.findViewById(R.id.bt1); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri .fromFile(new File(Environment .getExternalStorageDirectory(), "temp.jpg"))); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult(intent, 0); } });
} @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 0 && resultCode == Activity.RESULT_OK) { this.imageView.setImageDrawable(Drawable.createFromPath(new File( Environment.getExternalStorageDirectory(), "temp.jpg") .getAbsolutePath()));
}
}</pre>
本文由用戶 cme7 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!