Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert HTML to image (any format) on Android [closed]

Does anyone know how to convert html code (with images within it) to image on Android? I know how to make it on Java using JLabel/JEditorPane and BufferedImage, but now should make the same with Android.

like image 647
peter.tailor Avatar asked Jun 29 '11 18:06

peter.tailor


People also ask

Can we convert HTML to Android app?

To convert your HTML app to APK, you need to open HTML App Template on AppsGeyser, and insert your code. After that, you need to name the app and upload the icon. It takes up to 5 minutes to build an apk.

How do I get an image from HTML?

html file and insert it into the img code. Example: <img src=”(your image URL here)”> Save the HTML file. The next time you open it, you'll see the webpage with your newly added image.


1 Answers

The answer of @Neo1975 is worked for me, but to avoid using deprecated method WebView.capturePicture() you could use the following method to capture content of WebView.

/**
* WevView screenshot
*
* @param webView
* @return
*/
private static Bitmap screenshot(WebView webView) {
  webView.measure(View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    webView.layout(0, 0, webView.getMeasuredWidth(), 
    webView.getMeasuredHeight());
    webView.setDrawingCacheEnabled(true);
    webView.buildDrawingCache();
    Bitmap bitmap = Bitmap.createBitmap(webView.getMeasuredWidth(), 
    webView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    int iHeight = bitmap.getHeight();
    canvas.drawBitmap(bitmap, 0, iHeight, paint);
    webView.draw(canvas);
    return bitmap;
}

The idea behind it is using WebView.draw(Canvas) method.

like image 92
nhoxbypass Avatar answered Sep 28 '22 07:09

nhoxbypass