android - 如何在android中获得高质量的位图?
问题描述
如何在android中获得高质量的位图?
我做了一个 webView,因为我们有 spring web 项目。我们想在PDA中使用该项目并用蓝牙打印机打印一些标签。所以我做了一个 webView,我要打印带有标签的网页。但是“window.print”功能不适用于蓝牙打印机。因此,我尝试使用屏幕截图在 webView 中打印。
可悲的是,当我通过 android 中的 Bitmap.createBitmap 函数获取屏幕的位图时,它的质量真的很差。因此,它的印刷质量很差。我想要更好的打印分辨率。
如何获得更好的屏幕位图分辨率?
@RequiresApi(api = Build.VERSION_CODES.O) public Bitmap createBitmapFromView(View view) {
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;
}
解决方案
禁用位图缩放
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
推荐阅读
- cassandra - Cassandra 节点引导期间出现多个错误 - 'schema' 无效:null 并且发生流错误
- python - 如何计算以经度和纬度测量的两点之间的距离
- java - 我们如何从java中的字符串中删除“\”反斜杠字符?
- react-native - 导航参数缓存参数值并且在新值到位时不更新
- javascript - 如何在 Jasmine 1.3 中模拟此方法?
- java - 由于 API 不兼容,Maven 战争插件 3.0.0 出现问题
- android - 资源本地化的 Xamarin Android XML 错误
- azure - Microsoft.Azure.Kinect.BodyTracking.Dependencies.cuDNN 的 Visual Studio NuGet 还原失败
- asp.net-core-mvc - ASP.NET Core 3.1 MVC:将选中的复选框发送到控制器
- reactjs - React js Typescript“字符串”类型的参数不可分配给“SetStateAction”类型的参数
'