Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中从RelativeLayout创建位图_Android_Android Layout_Printing_Bitmap - Fatal编程技术网

在Android中从RelativeLayout创建位图

在Android中从RelativeLayout创建位图,android,android-layout,printing,bitmap,Android,Android Layout,Printing,Bitmap,我有一个RelativeLayout,想从中创建一个位图,并以字节的形式发送到蓝牙打印机。 根据设备分辨率,当我的位图生成更改textviews fontsize时-分辨率越高,fontsize越高。 如何在不考虑设备分辨率的情况下仅生成一个尺寸 我的代码: layout.setDrawingCacheEnabled(true); layout.measure(View.MeasureSpec.makeMeasureSpec(580, View.MeasureSpec.EXACTLY), Vie

我有一个RelativeLayout,想从中创建一个位图,并以字节的形式发送到蓝牙打印机。 根据设备分辨率,当我的位图生成更改textviews fontsize时-分辨率越高,fontsize越高。 如何在不考虑设备分辨率的情况下仅生成一个尺寸

我的代码:

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是我的纸张大小,在打印机上也可以

试试这个

      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;
}
试试这个

      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;
}