2011-09-08 121 views
2

任何人都可以引導我如何在顯示在ImageView組件上的圖像上放置不同的圖層。 基本上我想在我的繪圖應用程序中實現撤消和重做功能。在Android中通過ImageView繪製圖層

目前我可以把文字或圖畫放在圖像上,但不能實現撤銷/重做功能。我想知道這可以通過維護一些分層的東西來實現。

Plz幫助我。

這是事先我當前的繪圖代碼..

try { 

     image.buildDrawingCache(); 
     Bitmap bitmap = image.getDrawingCache(); 

     try 

     { 

      bitmap = getResizedBitmap(bitmap, image.getHeight(), 
        image.getWidth()); 

     } catch (OutOfMemoryError e) { 
      Toast.makeText(getApplicationContext(), e.getMessage(), 1) 
        .show(); 
     } 

     TextPaint tp = new TextPaint(); 
     tp.setColor(Color.GREEN); 
     tp.setAntiAlias(true); 
     tp.setTextSize(30); 

     Canvas canvas = new Canvas(bitmap); 
     canvas.drawText(input.getText().toString(), xPos, yPos, tp); 
     image.setImageBitmap(bitmap); 

     input.setText(""); 
     input.setVisibility(View.INVISIBLE); 

    } catch (Exception e) { 

     Toast.makeText(getApplicationContext(), e.getMessage(), 1).show(); 
    } 

感謝...!

回答

2

以另一種方式完成它。 創建orignal位圖並將其保存在一些位圖變量中。現在,在每個onDraw調用中啓動一個帶有orignal的位圖並將其傳遞給畫布。然後做你想做的事情。

+0

你能分享這個示例代碼嗎? – HourGlass

+1

現在已經過時了,我會尋找代碼,如果發現,它會幫助你。 –

+0

非常感謝... – HourGlass

0

嘗試LayerDrawable於Android

​​