如何在android中获得高质量的位图?
我做了一个webView,因为我们有spring web项目。我们希望在PDA中使用该项目,并使用蓝牙打印机打印一些标签。所以我做了一个webView,我要打印有标签的网页。但"window.print“功能不适用于蓝牙打印机。所以,我试着用截图在webView中打印。
遗憾的是,当我在安卓中通过Bitmap.createBitmap函数得到屏幕的位图时,它的质量真的很差。所以,它的打印质量很差。我想要更好的打印分辨率。
怎样才能获得更好的屏幕位图分辨率?
@RequiresApi(api = Build.VERSION_CODES.O)公共位图createBitmapFromView(视图视图){
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
//Pre-measure the view so that height and width don't remain null.
view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
//Assign a size and position to the view and all of its descendants
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
Bitmap bitmapa = Bitmap.createBitmap(width , height , Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
view.draw(c);
return bitmap;
}
发布于 2020-10-12 14:39:07
禁用位图缩放
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
https://stackoverflow.com/questions/64319935
复制相似问题