1

在我的应用程序中,我正在擦除图像,我需要撤消我的擦除,因为我正在捕获屏幕并保存。捕获它时不会擦除内容,应用程序变得很慢。为此,我试图在后台捕获,但在位图中捕获内容被最终图像覆盖。请帮助我如何解决这个问题。

public void getScreen1() {
    // TODO Auto-generated method stub
    File myDir=new File("/sdcard/saved_images");
    myDir.mkdirs();

    String fname = "final-"+ n +".jpg";
    File file = new File (myDir, fname);

    try {
        FileOutputStream ostream = new FileOutputStream(file);

        if(zoomView.getZoom()==1) {
            bitmapArray.compress(CompressFormat.PNG, 100, ostream);
        }
        else if(zoomView.getZoom()!=1) {
            bitmapArray=bitmap;
            bitmapArray.compress(CompressFormat.PNG, 100, ostream);
        }
        ostream.close();
    } 
    catch (Exception e) {
        e.printStackTrace();
    }
    String s="/sdcard/saved_images/"+fname;

    path.add(s);
    n++;
    Log.i("bitmap...111",""+bitmapArray);
}

//异步任务(用于后台运行)

class DownloadFileFromURL_dyn extends AsyncTask<String, String, String> {
    @Override
protected void onPreExecute() {
    super.onPreExecute();
    View content = findViewById(R.id.main_container);
    content.setDrawingCacheEnabled(true);
    bitmapArray= content.getDrawingCache();
    }

    @Override
protected String doInBackground(String... f_url) {
        getScreen1();
        return null;
}

@Override
protected void onProgressUpdate(String... progress) {
    // setting progress percentage
    }

    @Override
protected void onPostExecute(String file_url) {

    }
}

//画布触摸方法

@Override
public boolean onTouchEvent(MotionEvent event) {
    x = (int)event.getX();
    y = (int)event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if(path.size()==0) {
                String params="photo";
            new DownloadFileFromURL_dyn().execute(params);
            }
            touch_start(x, y);
            invalidate();
        break;
        case MotionEvent.ACTION_MOVE:
        touch_move(x, y);
        invalidate();
        break;
    case MotionEvent.ACTION_UP:
        touch_up();

        undo.setEnabled(true);
        String params="photo";
        new DownloadFileFromURL_dyn().execute(params);
        invalidate();
        break;
    }
return true;
}
4

0 回答 0