【问题标题】:How to get high quality bitmap in android?如何在android中获得高质量的位图?
【发布时间】:2021-01-26 21:21:16
【问题描述】:

如何在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;
}

【问题讨论】:

    标签: android bitmap


    【解决方案1】:

    禁用位图缩放

    Options options = new BitmapFactory.Options();
        options.inScaled = false;
        Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2023-02-21
      • 2013-01-11
      相关资源
      最近更新 更多