2017-09-19 6 views
0
나는 캔버스에 일부 텍스트와 이미지를 그리려는

에 캔버스에 이미지와 텍스트를 그릴,하지만 난 이미지를 그리기에 갇혔어요. 여기 안드로이드 -</p> <p><a href="https://i.stack.imgur.com/nLtsB.png" rel="nofollow noreferrer">The template would be something like this</a> 내가 텍스트를 그릴 관리, 다른 위치

나는

<ImageView 
     android:id="@+id/iv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:background="@drawable/border_ui" /> 

Bitmap bmp = Bitmap.createBitmap(949, 300, Bitmap.Config.ARGB_8888); 
 
     Canvas canvas = new Canvas(bmp); 
 

 
     TextPaint tp = new TextPaint(Paint.ANTI_ALIAS_FLAG); 
 
     tp.setColor(0xFF000000); 
 
     tp.setTextSize(15 * getApplicationContext().getResources().getDisplayMetrics().density + 0.5f); 
 
     tp.setShadowLayer(2, 0.5f, 0.5f, Color.BLACK); 
 
     StaticLayout sl = new StaticLayout("This is", 
 
       tp, 300, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false); 
 
     StaticLayout sm = new StaticLayout("This is", 
 
       tp, 300, Layout.Alignment.ALIGN_NORMAL, 1f, 0f, false); 
 

 

 
     canvas.save(); 
 
     canvas.translate(50, 20); //position text on the canvas 
 
     sl.draw(canvas); 
 
     canvas.restore(); 
 

 
     canvas.save(); 
 
     canvas.translate(50, 90); //position text on the canvas 
 
     sm.draw(canvas); 
 
     canvas.restore(); 
 

 
     ImageView iv = (ImageView) findViewById(R.id.iv); 
 
     iv.setImageBitmap(bmp);
방법 이미지를 그리는 어떤 생각을 무슨 짓입니까?

+0

왜 카드로 RelativeLayout, TextView와 ImageView가 각각 다른 4 가지 구성 요소를 사용해야합니까? 훨씬 더 쉬울 것입니다. – Eselfar

+0

왜냐하면 이미지를 내보내고 저장할 때 @Eselfar를 그릴 필요가 있기 때문입니다. –

답변

0
ImageView iv = (ImageView) findViewById(R.id.iv); 
iv.setImageBitmap(bmp); 
iv.draw(canvas); // Pass canvas to view to draw