Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android html to bitmap

public Bitmap getBitmap(final WebView w, int containerWidth, int containerHeight, final String baseURL, final String content) {
    final CountDownLatch signal = new CountDownLatch(1);
    final Bitmap b = Bitmap.createBitmap(containerWidth, containerHeight, Bitmap.Config.ARGB_8888);
    final AtomicBoolean ready = new AtomicBoolean(false); 
    w.post(new Runnable() {

        @Override
        public void run() {
            w.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    ready.set(true);
                }
            });
            w.setPictureListener(new PictureListener() {
                @Override
                public void onNewPicture(WebView view, Picture picture) {
                    if (ready.get()) {
                        final Canvas c = new Canvas(b);
                        view.draw(c);
                        w.setPictureListener(null);
                        signal.countDown();
                    }
                }
            });
            w.layout(0, 0, rect.width(), rect.height());
            w.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null);
        }});
    try {
        signal.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return b;
}
Comment

PREVIOUS NEXT
Code Example
Java :: last char in string java 
Java :: how to add element to end of array java 
Java :: min height bst leetcode 
Java :: viewpager2 dependency 
Java :: Simple gui in java 
Java :: set path in windows 
Java :: java create empty arraylist 
Java :: android application manifest 
Java :: sudoku solver 
Java :: how to find the length of a string in java without using length function 
Java :: java Program for Sum of the digits of a given number 
Java :: How to convert long to string android studio - java 
Java :: volley library 
Java :: find maximum in array java 
Java :: java check palindrome with string builder 
Java :: compile java 
Java :: java replace character 
Java :: convert fileinputstream to string java 
Java :: how to change checkbox color in android 
Java :: java formatted output 
Java :: java wait for user input 
Java :: insert string in string java 
Java :: Android Bitmap to Base64 String 
Java :: java method reference 
Java :: how to scan as a letter in java 
Java :: display two dimension array java 
Java :: constraintlayout vs coordinatorlayout 
Java :: cardview implementation 
Java :: math.min java 
Java :: Imageview on the bottom left of Imageview android anchor 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =