George Michael
George Michael

Reputation: 234

Get a part of the image from TextureView

I am using the code for cameras from Android Developers Samples to get a part of the image while in preview and perform some processing on it.

I want to get a square image from [0,0] to [99,99] of the preview, process it and show it in an ImageView on the fly. I tried getting the current image by entering the following code:

final Activity activity = getActivity();
activity.runOnUiThread(new Runnable() {
  @Override
  public void run() {
    final Bitmap originalBitmap = mTextureView.getBitmap();
    // more code here
 }
});

at this part of the code. By calling getBitmap(), it made the application extremely slow.

Is there an efficient way to get the square part I need in 1:1 ratio?

I know I can call getBitmap() with a smaller size and make it faster but I want to avoid losing data.

Upvotes: 1

Views: 1568

Answers (1)

Vlad
Vlad

Reputation: 8552

Whats for about this?

CustomView mTextureView = new CustomView(getApplicationContext());
new Task().execute(mTextureView.getBitmap());

and this is asynctask

 public class Task extends AsyncTask<Bitmap, Void, Void> {

    public Task() {

    }

    @Override
    protected Void doInBackground(Bitmap... objects) {
        //... do stuff
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
   }
}

Upvotes: 2

Related Questions