How to get high quality bitmap in android?
I made a webView since we have spring web project. Our wants to use the project in PDA and print some label with bluetooth printer. So I made a webView and Im going to print the web page have labels. But the "window.print" function is not working with bluetooth printer. So, I tried to print in webView with screenshot.
Sadly when I get the bitmap of the screen by Bitmap.createBitmap function in android, it was really bad quality. So, it was printed with bad quality. I want more good resolution of the print.
How can I get more good resolution of bitmap of the screen?
@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;
}
disable bitmap scaling
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.