简体   繁体   English

如何在Android的后台线程中处理位图?

[英]How do I process a bitmap in a background thread in Android?

I created an Android application where I can process the filter to a bitmap in the onCreate method of the layout. 我创建了一个Android应用程序,可以在布局的onCreate方法中将过滤器处理为位图。 However, I want to filter the bitmap in another thread instead of the UI thread. 但是,我想在另一个线程而不是UI线程中过滤位图。

Use an async task for the same 对同一任务使用异步任务
Let's say your global bitmap which you are displaying is mBitmap, tempbitmap on which you will do the processing is mBitmapTemp, 假设您要显示的全局位图是mBitmap,要对其进行处理的tempbitmap是mBitmapTemp,

class EditActionTask extends AsyncTask<Void, Void, Bitmap> {    

    @Override 
    protected Bitmap doInBackground(Void... params) {           
            int position = params[0];
            Bitmap mBitmapTemp= mBitmap.copy(mBitmap.getConfig(), true);
            Bitmap bitmap  = ; // do your editing
            return bitmap;
    }

    @Override protected void onPostExecute(Bitmap result) {
        // update ui from result butmap         
    }
}

And use it like this 像这样使用

EditActionTask editActionTask = new EditActionTask();
editActionTask.execute();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM