Html2Bitmap


Лицензия

Лицензия

MIT License
Группа

Группа

com.izettle
Идентификатор

Идентификатор

html2bitmap
Последняя версия

Последняя версия

1.10
Дата

Дата

Тип

Тип

aar
Описание

Описание

Html2Bitmap
Html2Bitmap
Ссылка на сайт

Ссылка на сайт

https://github.com/iZettle/android-html2bitmap
Система контроля версий

Система контроля версий

https://github.com/iZettle/android-html2bitmap

Скачать html2bitmap

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.izettle/html2bitmap/ -->
<dependency>
    <groupId>com.izettle</groupId>
    <artifactId>html2bitmap</artifactId>
    <version>1.10</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.izettle/html2bitmap/
implementation 'com.izettle:html2bitmap:1.10'
// https://jarcasting.com/artifacts/com.izettle/html2bitmap/
implementation ("com.izettle:html2bitmap:1.10")
'com.izettle:html2bitmap:aar:1.10'
<dependency org="com.izettle" name="html2bitmap" rev="1.10">
  <artifact name="html2bitmap" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.izettle', module='html2bitmap', version='1.10')
)
libraryDependencies += "com.izettle" % "html2bitmap" % "1.10"
[com.izettle/html2bitmap "1.10"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
androidx.annotation » annotation jar 1.0.2

Модули Проекта

Данный проект не имеет модулей.

Generate a bitmap from html on Android

Generates a bitmap of a defined width from html by rendering the content inside an off screen webview.

Does not block main thread.

Uses the webView available on the system so it's possibilities and limitations will be mirrored by the library.

Height will be calculated using WebView.getContentHeight()

Usage:

dependencies {
    implementation 'com.izettle:html2bitmap:1.9'
}
Bitmap bitmap = new Html2Bitmap.Builder(context: Context, content: WebViewContent).build().getBitmap();
  • context Used to create webview - application context is fine.
  • html The html that should be rendered to a bitmap.
  • width The requested width of the generated bitmap.
  • timeout Seconds before the job will terminate - if timeout is reached will call stopLoading() on the webview and return null.

Calls are blocking and hence recommended to be moved into a background thread.

Under the hood

Will wait for remote and local resources to load before generating bitmap i.e. "http://www.sample.com/image.jpg" will be downloaded before the screenshot is taken - take this into account before defining a timeout for the whole process.

Can be used anywhere you have access to a context. The purpose of the library was to perform its job inside a background thread and not to be tied to an activity.

Calls are synchronous to simplify usage in a background thread.

new AsyncTask<Void, Void, Bitmap>() {
    @Override
    protected Bitmap doInBackground(Void... voids) {
        String html = "<html><body><p>Hello world!</p><br/>Html bitmap</body><html>";
        
        return new Html2Bitmap.Builder().setContext(context).setContent(WebViewContent.html(html)).build().getBitmap();   
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        if (bitmap != null) {
            imageView.setImageBitmap(bitmap);
        }
    }
}.execute();

Note: Some of the methods on the webview are required to be run on the mainThread of the application - so some operations will be performed on that thread.

screenshot_1523608598

com.izettle

Zettle

Версии библиотеки

Версия
1.10
1.9
1.8
1.7
1.6
1.5
1.4