2017-06-21 8 views
1

私はRelativeLayoutを持っており、そこからビットマップを作成し、バイト単位でBluetoothプリンタに送信したいと考えています。 デバイス解像度に応じて、ビットマップが変更を生成するときにtextviews fontsize - 解像度が高くなるほど、フォントサイズが大きくなります。 デバイスの解像度に関係なく、どのように1つのサイズのみを生成できますか?AndroidでRelativeLayoutからビットマップを作成する

マイコード:

layout.setDrawingCacheEnabled(true); 
layout.measure(View.MeasureSpec.makeMeasureSpec(580, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(layout.getMeasuredHeight(), View.MeasureSpec.UNSPECIFIED)); 
layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); 
layout.buildDrawingCache(false); 
Bitmap sImagem = Bitmap.createBitmap(layout.getDrawingCache(false)); 
layout.setDrawingCacheEnabled(false); 

580は私の論文の大きさであり、そのプリンタでOKです!

答えて

0

はまだ機能していないこの

 private void takeScreenShot(){ 
     int totalHeight = mScreenshotLayout.getHeight(); 
     int totalWidth = mScreenshotLayout.getWidth(); 

     Bitmap b = getBitmapFromView(mScreenshotLayout,totalHeight,totalWidth); 
     SendingMail(b); 

     } 

     public Bitmap getBitmapFromView(View view, int totalHeight, int totalWidth) { 
     Bitmap returnedBitmap = Bitmap.createBitmap(totalWidth,totalHeight ,Bitmap.Config.ARGB_8888); 
     Canvas canvas = new Canvas(returnedBitmap); 
     Drawable bgDrawable = view.getBackground(); 
     if (bgDrawable != null) 
     bgDrawable.draw(canvas); 
    else 
     canvas.drawColor(Color.WHITE); 
    view.draw(canvas); 
    return returnedBitmap; 
} 
+0

を試してみてください... –

関連する問題