Android 无法使用叠加的位图图像提取图形缓存

Android 无法使用叠加的位图图像提取图形缓存,android,bitmap,android-canvas,Android,Bitmap,Android Canvas,我试图在SD卡上保存画布。基本上,我用onDraw(Canvas Canvas)方法绘制了两个位图(一个在另一个上面)。但是当我保存文件时,只存储底层位图。我在这里发布onDraw方法的代码: Paint paint = new Paint(); paint.setColor(Color.BLACK); //rectangle for the first image rct = new Rect(10, 10, canvas.getWidth(), canvas

我试图在SD卡上保存画布。基本上,我用onDraw(Canvas Canvas)方法绘制了两个位图(一个在另一个上面)。但是当我保存文件时,只存储底层位图。我在这里发布onDraw方法的代码:

    Paint paint = new Paint();
    paint.setColor(Color.BLACK);

    //rectangle for the first image
    rct = new Rect(10, 10, canvas.getWidth(), canvas.getHeight());

    // rectangle for the second image, the secong image is drawn where the user touches the screen
    new_image = new RectF(touchX, touchY, touchX + secondBitmap.getWidth(),
                touchY + secondBitmap.getHeight());

   //this is the bitmap that is drawn first
    canvas.drawBitmap(firstBitmap, null, rct, paint);

    //this is the bitmap drawn on top of the first bitmap on user touch
    canvas.drawBitmap(secondBitmap, null, new_image, paint);

    canvas.save();
将画布保存在写在MainActivity上的SD卡上的代码为:

   Bitmap bm = canvas.getDrawingCache() // canvas in an object of the class I extended from View
   String path = Environment.getExternalStorageDirectory()
            .getAbsolutePath();
   boolean exists = (new File(path)).exists();

   OutputStream outStream = null;
   File file = new File(path, "drawn_image" + ".jpg");

   try {
      outStream = new FileOutputStream(file);
      bmp.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
      outStream.flush();
      outStream.close();
      } 
   catch (FileNotFoundException e) {
    e.printStackTrace();
    } 
   catch (IOException e) {
        e.printStackTrace();
    }
问题在于,SD卡上只保存了基本图像(onDraw()方法的firstBitmap),而不是整个画布(包含两个图像)。我是canvas新手…因此,如果调用getDrawingcache()将使视图无效以获取完整缓存,请提供任何帮助。因此,调试您的代码并检查它是否正在查看onDraw()方法的每一行