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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With