0

It's been three days I'm looking for (and test) libs which can perform a generation of an image from textual content. I develop an app on Android with the Augmented Reality Metaio SDK. To apply a texture with text and image embed, I must generate a PNG file. So I need a method :

  • Compatible with Android
  • On the Android client : not generating the PNG on a server
  • With the right way like html/css, svg or Android layout for example : ie not having to make justify text and box positionning from scratch, I'm sure you understand why x)
  • Which can perform a generation in external thread (ie without the user have to see the layout)

I tested a lot of solutions, but nothing works.

Using WebView

Some topics about this :

Ultimately, onPageFinished is not enough and we must implement :

webView.setPictureListener(new PictureListener()
{
    @Override
    public void onNewPicture(WebView view, Picture picture)
    {
        [...]

It works, but it's deprecated and the WebView must be visible if I want to generate a png, and it does not suit me.

Using Android Layout

Some topics about this :

Once again, I must have a visible View to generate a PNG from it.

Using svg-android

Some topics about this :

It works, but there are only basic functions : include text, image or data-uri image don't work.

Using Batik

SVG Rasterizer and its use.

It works, but not on Android.

Conversion to Dalvik format failed with error 1

Community
  • 1
  • 1
hayj
  • 1,159
  • 13
  • 21

1 Answers1

0

I finally succeeded in using a WebView without having to see the view. I set the width to 0.1dp and switch visible/invisible quickly.

I use a WebView because the layout engine is more complete. But warning : as mentioned higher, the method onNewPicture is deprecated.

I implemented a class containing a GenerationProcess which perform all Thread treatments (on the UI Thread or on a backgroud Thread) and a GenerationQueue which perform a Thread ordering. So this class is totally independent and you can use it without having to think about the Thread you are.

With the Android Layout engine, we don't have to use all these Thread because there is no callback function like onPageFinished and onNewPicture : make your choice !

Github Project - WebView2Img

You can take a look at :

Then you can extends Page to manipulate the DOM (with jdom for example) to dynamicaly set content and save the html file.

EDIT : here an example of extends Page with dom manipulation before generation

hayj
  • 1,159
  • 13
  • 21