GetBitmapActivitypublic class GetBitmapActivity extends android.app.Activity implements TextureView.SurfaceTextureListener
Fields Summary |
---|
private android.hardware.Camera | mCamera | private android.view.TextureView | mTextureView |
Methods Summary |
---|
protected void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
FrameLayout content = new FrameLayout(this);
mTextureView = new TextureView(this);
mTextureView.setSurfaceTextureListener(this);
Button button = new Button(this);
button.setText("Copy bitmap to /sdcard/textureview.png");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap b = mTextureView.getBitmap();
try {
FileOutputStream out = new FileOutputStream(
Environment.getExternalStorageDirectory() + "/textureview.png");
try {
b.compress(Bitmap.CompressFormat.PNG, 100, out);
} finally {
try {
out.close();
} catch (IOException e) {
// Ignore
}
}
} catch (FileNotFoundException e) {
// Ignore
}
}
});
content.addView(mTextureView, new FrameLayout.LayoutParams(500, 400, Gravity.CENTER));
content.addView(button, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));
setContentView(content);
| public void | onSurfaceTextureAvailable(android.graphics.SurfaceTexture surface, int width, int height)
mCamera = Camera.open();
try {
mCamera.setPreviewTexture(surface);
} catch (IOException t) {
android.util.Log.e("TextureView", "Cannot set preview texture target!", t);
}
mCamera.startPreview();
| public boolean | onSurfaceTextureDestroyed(android.graphics.SurfaceTexture surface)
mCamera.stopPreview();
mCamera.release();
return true;
| public void | onSurfaceTextureSizeChanged(android.graphics.SurfaceTexture surface, int width, int height)
// Ignored, the Camera does all the work for us
| public void | onSurfaceTextureUpdated(android.graphics.SurfaceTexture surface)
// Ignored
|
|