FileDocCategorySizeDatePackage
GetBitmapActivity.javaAPI DocAndroid 5.1 API3679Thu Mar 12 22:22:44 GMT 2015com.android.test.hwui

GetBitmapActivity

public class GetBitmapActivity extends android.app.Activity implements TextureView.SurfaceTextureListener

Fields Summary
private android.hardware.Camera
mCamera
private android.view.TextureView
mTextureView
Constructors Summary
Methods Summary
protected voidonCreate(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 voidonSurfaceTextureAvailable(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 booleanonSurfaceTextureDestroyed(android.graphics.SurfaceTexture surface)

        mCamera.stopPreview();
        mCamera.release();
        return true;
    
public voidonSurfaceTextureSizeChanged(android.graphics.SurfaceTexture surface, int width, int height)

        // Ignored, the Camera does all the work for us
    
public voidonSurfaceTextureUpdated(android.graphics.SurfaceTexture surface)

        // Ignored