Android相机预览教程

Las*_*sse 5 camera android preview

我有一个关于我遵循的教程的问题.我想用相机预览制作一个Android应用程序,但直到现在我还没有找到任何一个很好的教程来展示如何做到这一点.这是链接教程 如果我可以使用"相机预制"的"有意图的相机",我不是很舒服吗?我该怎么办.

谢谢 :)

Vip*_*hah 17

以下教程将帮助您.

http://www.vogella.com/articles/AndroidCamera/article.html

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html

调用内置相机意图有图片.

public class demo extends Activity {

Button ButtonClick;
int CAMERA_PIC_REQUEST = 1337; 


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ButtonClick =(Button) findViewById(R.id.Camera);
    ButtonClick.setOnClickListener(new OnClickListener (){
        @Override
        public void onClick(View view)
        {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // request code

            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

        }
    });

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    if( requestCode == 1337)
    {
    //  data.getExtras()
        Bitmap thumbnail = (Bitmap) data.getExtras().get("data");

          Now you have received the bitmap..you can pass that bitmap to other activity
          and play with it in this activity or pass this bitmap to other activity
          and then upload it to server.
    }
    else 
    {
        Toast.makeText(demo.this, "Picture NOt taken", Toast.LENGTH_LONG);
    }
    super.onActivityResult(requestCode, resultCode, data);
}
}
Run Code Online (Sandbox Code Playgroud)