Using nl.siegmann.epublib I have taken a resource from a book which I try to actually display on the screen.
The api docs can be found here
The code I used are:
Book.getCoverImage() and Book.getCoverPage().
Actual Code looks more like this:
Book book = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView iv = (ImageView)findViewById(R.id.image_test);
try{
Resource res = bookLoaded().getCoverImage();
Bitmap bm = BitmapFactory.decodeStream(res.getInputStream());
iv.setImageBitmap(bm);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public Book bookLoaded(){
AssetManager am = getAssets();
try{
InputStream is = am.open("Ada Madison - [Sophie Knowles Mystery 01] - The Square Root of Murder (epub).epub");
book = (new EpubReader()).readEpub(is);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return book;
}
Now the problem I occurred was res was always null using .getCoverImage(). and I had an exception error when I tried .getCoverPage();
My question is “Is using BitmapFactory the proper way to do this?, am I doing something wrong?, or am I missing something?”.
To continue of what I researched so far:
You can get the .epub path. using book.GetHref(). However, the question is more of how can an .epub file(Similar to a zip file) get data inside of it. Then now I have to look for an extractor, and then I can find the image file.
try{
byte[] newData = bookLoaded().getCoverImage().getData();
Bitmap bmp =BitmapFactory.decodeByteArray(newData, 0, newData.length);
image_view.setImageBitmap(bmp);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
Somehow bookLoaded().getCoverImage().getData(); caused an exception
This was the lamest bug ever.
This code works. However the biggest issue is on .xml where textview overlapped the image and then did not show the image. This code may or may not work as the library will either create a location of it or not. If it does not you may have to look for it on .getResources().