2017-05-23 1 views
0

나는 그릴 수있는 ImageView의 서브 클래스를 가지고 있으며, EditText 서브 뷰 (드래그 가능하고 회전 가능)를 추가 할 수 있습니다.Xamarin 안드로이드는 비트 맵에서 편집 텍스트를 그립니다.

문제는 최종 이미지를 얻고 싶습니다. EditText을 새 이미지로 병합하는 방법이 확실하지 않습니다. 모든 도구가 캔버스에 직접 그려지기 때문에 마지막에 EditText 개의 텍스트를 그릴 필요가 있기 때문에 문제가됩니다. 사용자가 저장을 클릭하기 전에 드래그 가능하고 변경 가능해야합니다.

여러 가지 방법을 통해이 방법이 가장 정확하지만 텍스트를 어느 정도 회전하면 작동하지 않습니다.

public Bitmap GetFinalBitmap() 
    { 
     this.DrawingCacheEnabled = false; 
     this.DrawingCacheEnabled = true; 

     var finalImage = Bitmap.CreateBitmap(GetDrawingCache(true)); 
     foreach (var item in this.pathLists) 
     { 
      if (item.TextView != null) 
      { 
       item.TextView.BuildDrawingCache(true); 
       var txt = item.TextView.GetDrawingCache(true); 
       finalImage = Overlay(finalImage, txt, item.TextView.GetX(), item.TextView.GetY()); 
      } 
     } 

     return finalImage; 
    } 

    public Bitmap Overlay(Bitmap bmp1, Bitmap bmp2, float x, float y) 
    { 
     Bitmap bmOverlay = Bitmap.CreateBitmap(bmp1.Width, bmp1.Height, bmp1.GetConfig()); 
     Canvas canvas = new Canvas(bmOverlay); 
     canvas.DrawBitmap(bmp1, new Matrix(), null); 
     canvas.DrawBitmap(bmp2, x, y, null); 
     return bmOverlay; 
    } 

어떤 도움

은 (솔루션의 업데이트 나 ImageView's 비트 맵에 올바른 좌표 EditText을 그리는 방법에 어쩌면 새로운 접근 방식)을 감상 할 수있다.

답변

0

기본적으로 매트릭스를 사용하여 두 번째 비트 맵 (EditText 중 하나)을 그렸습니다. 다음은 회전 된 코드에도 적용됩니다. EditText.

public Bitmap Overlay(Bitmap bmp1, Bitmap bmp2, float x, float y, float rotation) 
    { 
     Bitmap bmOverlay = Bitmap.CreateBitmap(bmp1.Width, bmp1.Height, bmp1.GetConfig()); 
     Canvas canvas = new Canvas(bmOverlay); 
     canvas.DrawBitmap(bmp1, new Matrix(), null); 
     var matrix = new Matrix(); 
     matrix.Reset(); 
     if (rotation > 0) 
      matrix.PostRotate(rotation, bmp2.Width/2, bmp2.Height/2); 
     matrix.PostTranslate(x, y);  
     canvas.DrawBitmap(bmp2, matrix, null); 
     return bmOverlay; 
    } 
관련 문제