Android中的相机[关闭]
Posted
技术标签:
【中文标题】Android中的相机[关闭]【英文标题】:Camera in Android [closed] 【发布时间】:2011-08-10 18:55:15 【问题描述】:我想在安卓应用中使用相机功能。
我想在单击按钮控件时捕获图像,任何人都可以建议我最好的例子。
【问题讨论】:
请在本站搜索“android camera capture” 【参考方案1】:试试android dev的网站:Camera access in android也读这篇文章:Using android camera
有关更多信息,请查看此问题的相关部分。
【讨论】:
【参考方案2】:这里有一些问答供您开始使用:
Using the camera activity in Android
Use camera flashlight in Android
Android camera intent
How do I save data from Camera to disk using MediaStore on Android?
还有一些教程:
http://mobile.tutsplus.com/tutorials/android/android-sdk-quick-tip-launching-the-camera/
http://2008.hfoss.org/Tutorial:Creating_a_Camera_Application
http://www.androidph.com/2008/11/camera-capture.html
http://code.google.com/p/openmobster/wiki/CameraTutorial
【讨论】:
请指导关于 android.hardware.Camera2 示例更新 sdk 后无法解析 Listner 等某些类【参考方案3】:@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(id);
button.setonClickListener(new View.onClickListener()
public void onClick(View view)
Intent intent = new Intent();
intent.putExtra("aspectX", 730);
intent.putExtra("aspectY", 1115);
intent.putExtra("outputX", 730);
intent.putExtra("outputY", 1115);
intent.setAction("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, PICK_FROM_CAMERA);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode)
case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
Bitmap photo = (Bitmap) data.getExtras().get("data");
((ImageView)findViewById(R.id.selectedimage)).setImageBitmap(photo);
OutputStream outstream;
try
outstream = getContentResolver().openOutputStream(uri);
photo.compress(Bitmap.CompressFormat.JPEG,100, outstream);
outstream.close();
catch (FileNotFoundException e)
catch (IOException e)
break;
编辑:它完美且有效。如果您喜欢它,请尝试并提供反馈。
【讨论】:
【参考方案4】:请检查这个答案:
public class ImageUploading extends Activity
Uri imageUri = null;
ImageButton btnSubmit ;
public void onCreate(Bundle onsavedInstantState)
super.onCreate(onsavedInstantState);
setContentView(R.layout.edit_profile);
btnSubmit = (ImageButton) findViewById(R.id.btnSubmit);
btnSubmit.setClickable(true);
btnSubmit.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
File imgFile = new File(Environment.getExternalStorageDirectory(),"my_photo.png");
imageUri = Uri.fromFile(imgFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent,0);
);
@Override
public void onActivityResult(int RequestCode, int ResultCode, Intent imageIntent)
super.onActivityResult(RequestCode, ResultCode, imageIntent);
try
if(RequestCode == 0)
if(ResultCode == Activity.RESULT_OK)
getContentResolver().notifyChange(imageUri, null);
ContentResolver objContentResolver = getContentResolver();
Bitmap imgBitmap = android.provider.MediaStore.Images.Media.getBitmap(objContentResolver, imageUri);
Drawable imgDrawable = new BitmapDrawable(imgBitmap);
btnSubmit.setBackgroundDrawable(imgDrawable);
catch(Exception e)
它将在按钮单击时捕获图像,并将此图像设置为该按钮本身的背景图像。
【讨论】:
【参考方案5】:Hy 检查这些所有链接.. 我希望它对你有用。
http://www.softwarepassion.com/android-series-taking-photos-with-andorid-built-in-camera/
http://achorniy.wordpress.com/2010/04/26/howto-launch-android-camera-using-intents/
https://github.com/mistaguy/snapit/tree/master/src/com/mistaguy/snapit
http://mobile.tutsplus.com/tutorials/android/android-sdk-quick-tip-launching-the-camera/
http://notes.hfoss.org/index.php/Tutorial:Camera_and_Gallery_Demo
http://www.anddev.org/take_picture_from_camera_emulator-t168.html
【讨论】:
【参考方案6】:试试这个,如果不行我给你trunk链接。
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html
【讨论】:
以上是关于Android中的相机[关闭]的主要内容,如果未能解决你的问题,请参考以下文章