Professional Documents
Culture Documents
Camera
Camera
Outline
● Camera API
●
Basic usage
●
Take photo
Camera API
● Permissions
●
import android.hardware.Camera;
● Open/release
●
Constructor is private => Camera.open()
● Where is display?
●
Create your own extending
●
SurfaceView Add to activity using
setContentView
Image pipeline
Typical usage
Typical usage (contd.)
Typical usage (contd.)
Typical usage (contd.)
Demo
What is in byte[] data?
● Image byte by byte
●
PixelFormat – YUV/NV21, RGB565
●
Luckily many algorithms work in grayscale
●
YUV (YCbCr_420_SP/NV21)
What is in byte[] data? (contd.)
● YUV (YCbCr_420_SP/NV21)
●
Default format (on older versions the only
● available) Full greyscale (people are more
sensitive)
– First width*height bytes
What is in byte[] data? (contd.)
● RGB565 – 16 bits – 2 bytes per pixel
5 6 5
●
RRRRRGGG|GGGBBBBB
data[2n]
data[2n+1]
Take photo
String file = dir+filename+".jpg";
File newfile = new File(file);
try {
newfile.createNewFile();
} catch (IOException e) {}
Uri outputFileUri = Uri.fromFile(newfile);
Intent cameraIntent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK)
{ Log.d("CameraDemo", "Pic saved"); }
}