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